Implementing Code Formatting Standards in Agile Development
Integrate code formatting practices into agile workflows to enhance code quality and team collaboration.
0 likes
9 views
Rule Content
--- description: Enforce code formatting standards to enhance code quality and team collaboration in agile development. globs: ["**/*.js", "**/*.ts", "**/*.jsx", "**/*.tsx", "**/*.py", "**/*.java", "**/*.cs", "**/*.cpp", "**/*.php", "**/*.rb", "**/*.go"] tags: [code-formatting, agile-development, team-collaboration] priority: 1 version: 1.0.0 --- # Implementing Code Formatting Standards in Agile Development ## Context - **When to Apply**: Throughout the development lifecycle to maintain consistent code style. - **Prerequisites**: Team agreement on coding standards and integration of formatting tools into the development workflow. ## Requirements - **Consistent Indentation**: - JavaScript/TypeScript: Use 2 spaces for indentation. - Python: Use 4 spaces for indentation. - Java/C#/C++/PHP/Ruby/Go: Use 4 spaces for indentation. - **Line Length**: Limit lines to 80 characters to enhance readability. - **Naming Conventions**: - Use descriptive, meaningful names for variables, functions, and classes. - Follow language-specific naming conventions (e.g., camelCase for JavaScript variables, PascalCase for C# classes). - **Spacing**: - Ensure a single space after keywords and around operators. - Remove trailing whitespace at the end of lines. - **Braces and Brackets**: - Place opening braces on the same line as the statement (e.g., function, if, loop). - Ensure closing braces align with the start of the corresponding statement. - **Comments**: - Write clear, concise comments explaining complex logic. - Avoid redundant comments that state the obvious. - **Tool Integration**: - Integrate linters and formatters (e.g., ESLint for JavaScript, Pylint for Python) into the development workflow. - Configure tools to enforce the agreed-upon coding standards. ## Examples // Good: Consistent indentation and spacing function calculateTotal(price, taxRate) { const tax = price * taxRate; return price + tax; } // Bad: Inconsistent indentation and spacing function calculateTotal(price,taxRate){ const tax=price*taxRate; return price+tax; } # Good: Descriptive naming and consistent indentation def calculate_total(price, tax_rate): tax = price * tax_rate return price + tax # Bad: Non-descriptive naming and inconsistent indentation def calc(price, tax): t=price*tax return price+t // Good: Proper brace placement and spacing public class Calculator { public double calculateTotal(double price, double taxRate) { double tax = price * taxRate; return price + tax; } } // Bad: Improper brace placement and spacing public class Calculator{ public double calculateTotal(double price,double taxRate){ double tax=price*taxRate; return price+tax; } } // Good: Consistent indentation and naming conventions public class Calculator { public double CalculateTotal(double price, double taxRate) { double tax = price * taxRate; return price + tax; } } // Bad: Inconsistent indentation and naming conventions public class calculator{ public double calculate_total(double price,double tax_rate){ double tax=price*tax_rate; return price+tax; } } // Good: Proper brace placement and spacing class Calculator { public: double calculateTotal(double price, double taxRate) { double tax = price * taxRate; return price + tax; } }; // Bad: Improper brace placement and spacing class Calculator{ public: double calculateTotal(double price,double taxRate){ double tax=price*taxRate; return price+tax; } }; // Good: Consistent indentation and spacing class Calculator { public function calculateTotal($price, $taxRate) { $tax = $price * $taxRate; return $price + $tax; } } // Bad: Inconsistent indentation and spacing class Calculator{ public function calculateTotal($price,$taxRate){ $tax=$price*$taxRate; return $price+$tax; } } # Good: Consistent indentation and naming conventions class Calculator def calculate_total(price, tax_rate) tax = price * tax_rate price + tax end end # Bad: Inconsistent indentation and naming conventions class calculator def calculateTotal(price,taxRate) tax=price*taxRate price+tax end end // Good: Proper brace placement and spacing package main import "fmt" func calculateTotal(price, taxRate float64) float64 { tax := price * taxRate return price + tax } func main() { fmt.Println(calculateTotal(100, 0.2)) } // Bad: Improper brace placement and spacing package main import "fmt" func calculateTotal(price,taxRate float64)float64{ tax:=price*taxRate return price+tax } func main(){ fmt.Println(calculateTotal(100,0.2)) }