agentleFS
nohemi20231nohemi20231/design-skills/skills/clean-code/SKILL.md

clean-code

Skill0 starsChanged 14 days agoApache-2.0View on GitHub

Use when writing, refactoring, or reviewing code at the function, class, and module level: naming, function design, SOLID, error handling, tests, and code smells.

108 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use intelligent-routing, nextjs-react-expert and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • SKB3002Skill

    intelligent-routing

    Automatic agent selection and intelligent task routing. Analyzes user requests and automatically selects the best specialist agent(s) without requiring explicit user mentions.

    Also in 5 projects that use this

  • SKB3002Skill

    nextjs-react-expert

    React and Next.js performance optimization from Vercel Engineering. Use when building React components, optimizing performance, eliminating waterfalls, reducing bundle size, reviewing code for performance issues, or implementing server/client-side optimizations.

    Also in 3 projects that use this

  • xfstudioSkill

    bash-pro

    Master of defensive Bash scripting for production automation, CI/CD

    Also in 4 projects that use this

  • xfstudioSkill

    code-refactoring-tech-debt

    You are a technical debt expert specializing in identifying, quantifying, and prioritizing technical debt in software projects. Analyze the codebase to uncover debt, assess its impact, and create acti

    Also in 4 projects that use this

  • flying-diceSkill

    clean-code-review

    Multi-agent clean code audit — each principle gets its own agent

    Also in 3 projects that use this

  • goca-seSkill

    batch-operations

    Apply a change safely across many files — refactors touching more than 5 files, library or API migrations, project-wide renames of symbols/imports/paths, or adding boilerplate to many files. Use when "do it all at once" risks context overflow or silent failures.

    Also in 3 projects that use this

  • +4 more from xfstudio

The file

Show its rules and text

We split this skill into the rules it gives an agent

35 rules. 0 are common, 26 are distinctive, and 9 are very specific to this project.

  • 0

    Common

    Most of the 101 edited versions we read keep these.

  • 26

    Distinctive

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When principles conflict, choose deliberately and state the trade-off in one line (see Tensions).

    line 13
  2. Distinctive:

    When reviewing, order findings by severity: correctness, then design, then readability, then style.

    line 14
  3. Very specific:

    Avoid abbreviations, type encodings, and noise words (Manager, Data, Info, Helper) unless they are real domain terms.

    line 18
  4. Very specific:

    Use one word per concept across the codebase.

    line 20
  5. Distinctive:

    Keep functions small. If you need a comment or blank line to separate sections, extract a function.

    line 25
  6. Distinctive:

    Use three parameters or fewer.

    line 26
  7. Distinctive:

    Don't use boolean flag arguments.

    line 27
  8. Distinctive:

    Avoid hidden side effects.

    line 28
  9. Distinctive:

    Prefer returning new values to mutating arguments.

    line 29
  10. Distinctive:

    ISP: prefer small, client-specific interfaces to fat ones.

    line 36
  11. Distinctive:

    Prefer composition to inheritance.

    line 42
  12. Distinctive:

    Prefer immutability: final fields and value objects.

    line 44
  13. Very specific:

    Avoid primitive obsession.

    line 45
  14. Distinctive:

    KISS: use the simplest design that works.

    line 49
  15. Distinctive:

    YAGNI: don't build for requirements you don't have yet.

    line 50
  16. Distinctive:

    Boy Scout rule: leave code cleaner than you found it.

    line 52
  17. Distinctive:

    No magic numbers or strings.

    line 53
  18. Distinctive:

    Delete commented-out code, redundant comments, and change-log comments.

    line 57
  19. Distinctive:

    Every TODO needs an owner or a ticket.

    line 58
  20. Very specific:

    Don't return null. Return Optional, an empty collection, or a Null Object.

    line 62
  21. Very specific:

    Never swallow exceptions. Catch generic Exception only at a top-level boundary.

    line 65
  22. Distinctive:

    Keep try blocks small and separate error handling from the happy path.

    line 66
  23. Distinctive:

    Don't use exceptions for control flow.

    line 67
  24. Distinctive:

    Follow FIRST: fast, independent, repeatable, self-validating, and timely.

    line 70
  25. Distinctive:

    Test behavior through the public API, not implementation details.

    line 72
  26. Distinctive:

    Follow the project's formatter and linter.

    line 77
  27. Distinctive:

    Keep related code close together and order it top-down, callers before callees.

    line 78
  28. Distinctive:

    Keep concurrency mechanics separate from business logic.

    line 82
  29. Distinctive:

    Small functions vs. readability: don't fragment logic into one-line wrappers that force constant jumping between functions.

    line 100
  30. Distinctive:

    Performance vs. clarity: write for clarity first. Optimize measured hotspots and comment why.

    line 102
  31. Very specific:

    Use constructor injection with final fields.

    line 105
  32. Distinctive:

    Keep controllers thin: map HTTP to DTOs and delegate to services.

    line 106
  33. Very specific:

    Never expose JPA entities through the API.

    line 107
  34. Very specific:

    Put @Transactional at the service or use-case boundary, not on controllers.

    line 108
  35. Very specific:

    Use Optional only as a return type, never for fields or parameters.

    line 109

“Common” is measured: kept by at least 6 in 10 of the 101 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Clean Code

Apply this skill whenever you produce or review code. System structure questions (service boundaries, layering across the system, data ownership) belong to the software-architecture skill. For the test-first workflow, use the tdd skill. For the reasoning behind a design choice (is this good design, is it over-engineered, which non-functional requirements matter), use the software-design skill. When planning or reviewing a refactor, use the refactor-proposal skill.

How to apply

  1. Make it correct and covered by tests first. Then clean it.
  2. Walk every section below. Fix what matters and don't gold-plate.
  3. When principles conflict, choose deliberately and state the trade-off in one line (see Tensions).
  4. When reviewing, order findings by severity: correctness, then design, then readability, then style. Name the principle and show the fix in code.

Naming

  • Names reveal intent: what it is and why it exists, not how it works.
  • Avoid abbreviations, type encodings, and noise words (Manager, Data, Info, Helper) unless they are real domain terms.
  • Classes are nouns, methods are verbs, and booleans read as predicates (isActive, hasExpired).
  • Use one word per concept across the codebase. Pick one of get, fetch, or retrieve.
  • Name length grows with scope. Short names are fine for tiny scopes, and wide scopes need descriptive names.

Functions

  • A function does one thing at one level of abstraction. Read top-down (stepdown rule).
  • Keep functions small. If you need a comment or blank line to separate sections, extract a function.
  • Use three parameters or fewer. Group related ones into a parameter object.
  • Don't use boolean flag arguments. Split into two well-named methods.
  • Avoid hidden side effects. Apply command-query separation: a function either changes state or returns a value.
  • Prefer returning new values to mutating arguments.

Classes and modules

SOLID

  • SRP: one reason to change, meaning one actor or stakeholder.
  • OCP: extend behavior by adding types or strategies, not by editing switch statements.
  • LSP: subtypes honor the base contract. Don't override a method only to throw UnsupportedOperationException.
  • ISP: prefer small, client-specific interfaces to fat ones.
  • DIP: depend on abstractions. High-level policy never imports low-level detail.

Also

  • High cohesion inside a unit, low coupling between units.
  • Law of Demeter: talk to direct collaborators. Avoid chains like a.getB().getC().doX().
  • Prefer composition to inheritance.
  • Tell, don't ask: put behavior next to the data it uses. Getters and setters that expose internals are fine only on DTOs.
  • Prefer immutability: final fields and value objects.
  • Avoid primitive obsession. Introduce value types such as EmailAddress, Money, and OrderId.

General principles

  • DRY applies to knowledge, not text. Two similar code blocks that change for different reasons are not duplication.
  • KISS: use the simplest design that works.
  • YAGNI: don't build for requirements you don't have yet.
  • Least astonishment: code does what its name and signature suggest.
  • Boy Scout rule: leave code cleaner than you found it. Keep refactors in separate commits from behavior changes.
  • No magic numbers or strings. Use named constants or enums.

Comments

  • Code explains how. Comments explain why: constraints, non-obvious decisions, warnings, and public API contracts.
  • Delete commented-out code, redundant comments, and change-log comments.
  • Every TODO needs an owner or a ticket.

Error handling

  • Throw exceptions rather than returning error codes.
  • Don't return null. Return Optional, an empty collection, or a Null Object.
  • Fail fast and validate input at boundaries.
  • Throw specific exception types with useful context.
  • Never swallow exceptions. Catch generic Exception only at a top-level boundary.
  • Keep try blocks small and separate error handling from the happy path.
  • Don't use exceptions for control flow.

Tests

  • Follow FIRST: fast, independent, repeatable, self-validating, and timely.
  • Each test covers one behavior, uses Arrange-Act-Assert, and has a descriptive name (shouldRejectOrder_whenStockIsInsufficient).
  • Test behavior through the public API, not implementation details.
  • Hold test code to production standards.
  • Design for testability: inject dependencies and avoid static or global state.

Formatting

  • Follow the project's formatter and linter. Consistency beats personal preference.
  • Keep related code close together and order it top-down, callers before callees.

Concurrency (when relevant)

  • Minimize shared mutable state. Prefer immutable data and thread confinement.
  • Keep concurrency mechanics separate from business logic.

Code smells and refactorings

SmellRefactoring
Long methodExtract Method
Large class / god serviceExtract Class, split by use case
Long parameter listIntroduce Parameter Object
Feature envyMove Method
Data clumps, primitive obsessionIntroduce Value Object
Switch on typeReplace Conditional with Polymorphism
Shotgun surgeryMove related logic together
Divergent changeSplit by reason to change
Message chainsHide Delegate
Speculative generality, dead codeDelete it

Tensions between principles

  • DRY vs. decoupling: across module or service boundaries, accept duplication rather than create shared coupling.
  • Small functions vs. readability: don't fragment logic into one-line wrappers that force constant jumping between functions.
  • Abstraction vs. YAGNI: introduce an abstraction at the second or third concrete case (rule of three), not the first.
  • Performance vs. clarity: write for clarity first. Optimize measured hotspots and comment why.

Java / Spring Boot notes

  • Use constructor injection with final fields. Don't use field @Autowired.
  • Keep controllers thin: map HTTP to DTOs and delegate to services.
  • Never expose JPA entities through the API. Map them to DTOs, and use records for DTOs and value objects.
  • Put @Transactional at the service or use-case boundary, not on controllers.
  • Use Optional only as a return type, never for fields or parameters.
  • Centralize exception-to-HTTP mapping in @RestControllerAdvice.
  • Split god services by use case.

Review output format

For each finding, give:

  • the location
  • the principle it violates
  • the problem
  • the suggested fix, in code

End with the top three priorities. Skip anything the formatter already handles.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.