Customizing Code Formatters for Project-Specific Standards
Configure code formatting tools to align with unique project or organizational coding standards.
0 likes
9 views
Rule Content
--- description: Configure code formatters to align with unique project or organizational coding standards globs: ['**/*.js', '**/*.ts', '**/*.jsx', '**/*.tsx', '**/*.py', '**/*.java', '**/*.cs', '**/*.cpp', '**/*.php', '**/*.rb', '**/*.go'] tags: [code-formatting, project-standards, consistency] priority: 3 version: 1.0.0 --- # Customizing Code Formatters for Project-Specific Standards ## Context - This rule applies to all source code files within the project. - Ensures that code formatting adheres to the project's unique coding standards, enhancing readability and maintainability. ## Requirements - **JavaScript/TypeScript**: Use 2 spaces for indentation. Apply Prettier with a configuration file (`.prettierrc`) that reflects project-specific rules. - **Python**: Use 4 spaces for indentation. Apply Black with a configuration file (`pyproject.toml`) that reflects project-specific rules. - **Java**: Use 4 spaces for indentation. Apply Checkstyle with a configuration file (`checkstyle.xml`) that reflects project-specific rules. - **C#**: Use 4 spaces for indentation. Apply EditorConfig with a configuration file (`.editorconfig`) that reflects project-specific rules. - **C++**: Use 4 spaces for indentation. Apply ClangFormat with a configuration file (`.clang-format`) that reflects project-specific rules. - **PHP**: Use 4 spaces for indentation. Apply PHP_CodeSniffer with a configuration file (`phpcs.xml`) that reflects project-specific rules. - **Ruby**: Use 2 spaces for indentation. Apply RuboCop with a configuration file (`.rubocop.yml`) that reflects project-specific rules. - **Go**: Use tabs for indentation. Apply gofmt with a configuration file (`.gofmt`) that reflects project-specific rules. ## Examples // Good: JavaScript code formatted with 2-space indentation function greet(name) { console.log(`Hello, ${name}!`); } // Bad: JavaScript code with inconsistent indentation function greet(name) { console.log(`Hello, ${name}!`); } # Good: Python code formatted with 4-space indentation def greet(name): print(f"Hello, {name}!") # Bad: Python code with inconsistent indentation def greet(name): print(f"Hello, {name}!")