Standardizing Code Comment Formatting for Better Documentation
Define and apply consistent formatting rules for code comments to enhance documentation quality.
0 likes
13 views
Rule Content
# Title: Standardizing Code Comment Formatting for Better Documentation # Description: Define and apply consistent formatting rules for code comments to enhance documentation quality. # Category: Code Formatting # Category Context: Ensures consistent style in code by handling indentation, spacing, line breaks, and overall structure to keep code clean and readable. rules: - id: comment-formatting description: "Ensure consistent and clear formatting of code comments to improve documentation quality." severity: warning languages: [javascript, python, java, csharp] pattern: | //.*|/\*[\s\S]*?\*/|#.* message: "Review comment formatting to ensure clarity and consistency." fix: | # Guidelines for Comment Formatting: # 1. Use complete, capitalized sentences ending with proper punctuation. [GNU Coding Standards](https://en.wikipedia.org/wiki/GNU_coding_standards) # 2. Place comments on separate lines above the code they describe, not at the end of a line. [Ed-Fi Tech Docs](https://edfi.atlassian.net/wiki/spaces/ETKB/pages/20874867/Coding%2BStandards%2B-%2BGeneral%2BPrinciples) # 3. Avoid redundant comments that state the obvious; focus on explaining the 'why' behind complex logic. [Restackio](https://www.restack.io/p/automated-code-review-with-ai-answer-best-practices-code-comments-cat-ai) # 4. Use proper grammar, punctuation, and formatting to ensure readability. [iEdgeSoft Blog](https://www.iedgesoft.com/blog/2023/11/07/10-rules-of-effective-coding-part-1/) # 5. Update comments during refactoring to keep them accurate and relevant. [iEdgeSoft Blog](https://www.iedgesoft.com/blog/2023/11/07/10-rules-of-effective-coding-part-1/) # 6. Use inline comments sparingly; prefer self-explanatory code. [Restackio](https://www.restack.io/p/automated-code-review-with-ai-answer-best-practices-code-comments-cat-ai) # 7. Provide context in comments for complex algorithms or non-standard approaches. [Restackio](https://www.restack.io/p/automated-code-review-with-ai-answer-best-practices-code-comments-cat-ai) # 8. Avoid formatted blocks of asterisks around comments. [Ed-Fi Tech Docs](https://edfi.atlassian.net/wiki/spaces/ETKB/pages/20874867/Coding%2BStandards%2B-%2BGeneral%2BPrinciples) # 9. Use TODO comments to mark incomplete code, but ensure they are addressed before final merges. [MIT Communication Lab](https://mitcommlab.mit.edu/meche/commkit/coding-and-comment-style/) # 10. Write comments in English to ensure accessibility for all developers. [GNU Coding Standards](https://en.wikipedia.org/wiki/GNU_coding_standards)