Establishing a Consistent Code Formatting Style in Python
Learn how to create and maintain a uniform code formatting style using tools like Black and Flake8 to enhance readability across your Python projects.
0 likes
9 views
Rule Content
{ "title": "Establishing a Consistent Code Formatting Style in Python", "description": "Learn how to create and maintain a uniform code formatting style using tools like Black and Flake8 to enhance readability across your Python projects.", "category": "Python Cursor Rules", "rules": [ { "name": "Adhere to PEP 8 Standards", "description": "Ensure all Python code complies with PEP 8 guidelines to maintain consistency and readability.", "implementation": [ "Use 4 spaces per indentation level.", "Limit all lines to a maximum of 79 characters.", "Use lowercase with underscores for function and variable names.", "Use CapitalizedWords for class names.", "Use ALL_CAPS with underscores for constants." ] }, { "name": "Automate Formatting with Black", "description": "Utilize Black to automatically format code, ensuring uniform style across the codebase.", "implementation": [ "Install Black using pip: `pip install black`.", "Format files by running: `black <file_or_directory>`.", "Integrate Black into the development workflow to enforce consistent formatting." ] }, { "name": "Enforce Linting with Flake8", "description": "Use Flake8 to identify and enforce coding style violations.", "implementation": [ "Install Flake8 using pip: `pip install flake8`.", "Run Flake8 to check code: `flake8 <file_or_directory>`.", "Address all reported issues to maintain code quality." ] }, { "name": "Integrate Tools into Development Workflow", "description": "Incorporate Black and Flake8 into the development process to ensure continuous adherence to coding standards.", "implementation": [ "Configure pre-commit hooks to run Black and Flake8 before each commit.", "Set up continuous integration pipelines to include formatting and linting checks.", "Regularly review and update configurations to align with project requirements." ] }, { "name": "Document Formatting Standards", "description": "Maintain clear documentation of the project's code formatting standards for team reference.", "implementation": [ "Create a CONTRIBUTING.md file outlining the use of Black and Flake8.", "Provide examples of correct formatting and common pitfalls.", "Encourage team members to follow documented guidelines to ensure consistency." ] } ] }