code-clean.mdc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ---
  2. description:
  3. globs:
  4. alwaysApply: true
  5. ---
  6. ---
  7. description: Guidelines for writing clean, maintainable, and human-readable code. Apply these rules when writing or reviewing code to ensure consistency and quality.
  8. globs:
  9. ---
  10. # Clean Code Guidelines
  11. ## Constants Over Magic Numbers
  12. - Replace hard-coded values with named constants
  13. - Use descriptive constant names that explain the value's purpose
  14. - Keep constants at the top of the file or in a dedicated constants file
  15. ## Meaningful Names
  16. - Variables, functions, and classes should reveal their purpose
  17. - Names should explain why something exists and how it's used
  18. - Avoid abbreviations unless they're universally understood
  19. ## Smart Comments
  20. - Don't comment on what the code does - make the code self-documenting
  21. - Use comments to explain why something is done a certain way
  22. - Document APIs, complex algorithms, and non-obvious side effects
  23. ## Single Responsibility
  24. - Each function should do exactly one thing
  25. - Functions should be small and focused
  26. - If a function needs a comment to explain what it does, it should be split
  27. ## DRY (Don't Repeat Yourself)
  28. - Extract repeated code into reusable functions
  29. - Share common logic through proper abstraction
  30. - Maintain single sources of truth
  31. ## Clean Structure
  32. - Keep related code together
  33. - Organize code in a logical hierarchy
  34. - Use consistent file and folder naming conventions
  35. ## Encapsulation
  36. - Hide implementation details
  37. - Expose clear interfaces
  38. - Move nested conditionals into well-named functions
  39. ## Code Quality Maintenance
  40. - Refactor continuously
  41. - Fix technical debt early
  42. - Leave code cleaner than you found it
  43. ## Testing
  44. - Write tests before fixing bugs
  45. - Keep tests readable and maintainable
  46. - Test edge cases and error conditions
  47. ## Version Control
  48. - Write clear commit messages
  49. - Make small, focused commits
  50. - Use meaningful branch names