PluginBench
Rule

clean code

via PatrickJS/awesome-cursorrules

Guidelines for writing clean, maintainable, and human-readable code.

What is clean code?

This rule provides best practices for code quality across all languages and frameworks. Apply it when writing or reviewing code to ensure consistency, readability, and long-term maintainability through principles like meaningful naming, single responsibility, and continuous refactoring.

  • Replace magic numbers with named constants that explain purpose
  • Use descriptive variable, function, and class names that reveal intent
  • Write self-documenting code with comments explaining why, not what
  • Keep functions small and focused on a single responsibility
  • Extract repeated code into reusable functions to maintain DRY principle
  • Organize code logically with clear file structure and naming conventions

Applies to

File patterns this rule matches.

["**/*"]
Rule definition (reference)

Source of truth, from the repository.

Clean Code Guidelines

Constants Over Magic Numbers

  • Replace hard-coded values with named constants
  • Use descriptive constant names that explain the value's purpose
  • Keep constants at the top of the file or in a dedicated constants file

Meaningful Names

  • Variables, functions, and classes should reveal their purpose
  • Names should explain why something exists and how it's used
  • Avoid abbreviations unless they're universally understood

Smart Comments

  • Don't comment on what the code does - make the code self-documenting
  • Use comments to explain why something is done a certain way
  • Document APIs, complex algorithms, and non-obvious side effects

Single Responsibility

  • Each function should do exactly one thing
  • Functions should be small and focused
  • If a function needs a comment to explain what it does, it should be split

DRY (Don't Repeat Yourself)

  • Extract repeated code into reusable functions
  • Share common logic through proper abstraction
  • Maintain single sources of truth

Clean Structure

  • Keep related code together
  • Organize code in a logical hierarchy
  • Use consistent file and folder naming conventions

Encapsulation

  • Hide implementation details
  • Expose clear interfaces
  • Move nested conditionals into well-named functions

Code Quality Maintenance

  • Refactor continuously
  • Fix technical debt early
  • Leave code cleaner than you found it

Testing

  • Write tests before fixing bugs
  • Keep tests readable and maintainable
  • Test edge cases and error conditions

Version Control

  • Write clear commit messages
  • Make small, focused commits
  • Use meaningful branch names

Related rules

Set up email-to-Telegram forwarding via Cloudflare Email Routing and Workers using mail2tg CLI.

**/*
41k
via PatrickJS/awesome-cursorrules

Full-stack SaaS on Cloudflare Workers with Hono APIs, Angular frontends, and enterprise integrations.

**/*
41k
via PatrickJS/awesome-cursorrules

Code development guidelines for precise, efficient AI-assisted changes without unnecessary commentary.

**/*
41k
via PatrickJS/awesome-cursorrules

Guidelines for writing clean, interview-ready code during pair programming sessions.

**/*
41k
via PatrickJS/awesome-cursorrules

Analyze codebase patterns and adapt new code to match established style conventions.

**/*
41k
via PatrickJS/awesome-cursorrules

Enforce disciplined code review practices and focused AI assistance behavior.

["**/*"]
41k
via PatrickJS/awesome-cursorrules