agentleFS
techygargtechygarg/lattice/skills/clean-code/SKILL.md

clean-code

Skill197 starsChanged 3 months agoMITView on GitHub

Apply clean code principles when generating or modifying implementation code. Enforces function focus, naming clarity, complexity management, error handling, and self-documenting style. Use when the user mentions 'clean code', 'code quality', 'coding guidelines', or 'implementation quality'. Loaded automatically by the code-generating molecules (code-forge, refactor-safely, bug-fix). This skill governs the craft of writing individual code units -- not architecture (see architecture), not security posture (see secure-coding), not test structure (see test-quality), and not refactoring workflows (see refactor-safely).

63 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use 2d-games, 3d-games 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.
  • tiendatworkSkill

    2d-games

    2D game development principles. Sprites, tilemaps, physics, camera.

    Also in 3 projects that use this

  • tiendatworkSkill

    3d-games

    3D game development principles. Rendering, shaders, physics, cameras.

    Also in 3 projects that use this

  • MindrallySkill

    clean-architecture

    Guidelines for implementing Clean Architecture patterns in Flutter and Go applications, with emphasis on separation of concerns, dependency rules, and testability.

    Also in 7 projects that use this

  • ratacatSkill

    design-patterns

    Use when designing software architecture, refactoring code structure, solving recurring design problems, or when code exhibits symptoms like tight coupling, rigid hierarchies, scattered responsibilities, or difficult-to-test components. Also use when choosing between architectural approaches or reviewing code for structural improvements.

    Also in 5 projects that use this

  • kayamanSkill

    solid-principles

    Enforces SOLID principles (SRP, OCP, LSP, ISP, DIP) in object-oriented and multi-paradigm code. Use when designing classes and interfaces, evaluating responsibility assignment, reviewing code for coupling issues, applying dependency inversion, refactoring fat interfaces, or checking that subtypes are truly substitutable.

    Also in 3 projects that use this

  • DIL8654Skill

    logging-patterns

    Keep logs structured, correlated, low-noise, and safe for production support. Use when adding operational logging, reviewing observability, or improving diagnostics in .NET services.

    Also in 3 projects that use this

  • +6 more from tiendatwork

The file

We split this skill into the rules it gives an agent

9 rules. 0 are common, 3 are distinctive, and 6 are very specific to this project.

  • 0

    Common

    Most of the 59 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 6

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Read .lattice/config.yaml in the repo root.

    line 11
  2. Very specific:

    If found, check paths.clean_code for a custom document path.

    line 12
  3. Very specific:

    If a custom document exists at that path, read it and check its YAML frontmatter for mode:

    line 13
  4. Very specific:

    If a custom path is configured but no document exists at it → tell the user which configured path is missing, then fall back to …

    line 16
  5. Very specific:

    If there is no config file or no paths.clean_code key, read ./references/defaults.md.

    line 17
  6. Very specific:

    Language adaptation: if paths.language_idioms is set in the config and the document exists, read it and adapt the defaults using these …

    line 18
  7. Distinctive:

    Project-specific checks: if the loaded doc (from Config Resolution) contains a Validation Checklist section (§10 from the …

    line 38
  8. Distinctive:

    All checks pass → state "Passes clean-code.

    line 40
  9. Distinctive:

    After the checklist, scan for each of these.

    line 44

“Common” is measured: kept by at least 6 in 10 of the 59 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

Config Resolution

Projects can customize this skill's standards. Resolution order:

  1. Read .lattice/config.yaml in the repo root.
  2. If found, check paths.clean_code for a custom document path.
  3. If a custom document exists at that path, read it and check its YAML frontmatter for mode:
    • mode: override: the custom document has full precedence. Use it instead of the embedded defaults. It must be comprehensive -- treat it as the sole reference.
    • mode: overlay (or no mode field): read the embedded ./references/defaults.md first, then apply the custom document's sections on top. A custom section replaces the matching default section (matched by exact heading); new sections append after the defaults.
  4. If a custom path is configured but no document exists at it → tell the user which configured path is missing, then fall back to ./references/defaults.md.
  5. If there is no config file or no paths.clean_code key, read ./references/defaults.md.
  6. Language adaptation: if paths.language_idioms is set in the config and the document exists, read it and adapt the defaults using these sections:
    • "Error Handling" → adapt §8 (Error Handling) patterns to the language's idioms. Language idioms take precedence over the pseudocode defaults.
    • "Type System & Object Model" → adapt §1 (Single Responsibility) cohesion guidance to the language's constructs (e.g., struct vs class).
    • "Naming Conventions" → adapt §4 (Meaningful Naming) patterns to the language's conventions.
    • "Parameter & Function Design" → adapt §2 (Small, Focused Functions) and §5 (Parameter Design) to the language's capabilities.
    • "Dependency Management" → adapt §9 (Test-Friendly Code) dependency-injection patterns to the language's idioms.

Self-Validation Checklist

STOP after generating each component. Verify ALL checks. Fix every failed check before presenting. Judgment calls → present options (see Ambiguity Signals).

  1. SINGLE RESPONSIBILITY: Can you describe each function without "and"? If not → extract a separate function.
  2. SIZE: Is each function under the size threshold from the loaded doc (~20 lines default)? If not → extract a sub-operation into its own named function.
  3. COMPLEXITY: Is cyclomatic complexity under the threshold from the loaded doc (~10 default)? If not → flatten with a guard clause or extract a branch.
  4. ABSTRACTION LEVEL: Does each function operate at one level of abstraction? If high-level logic mixes with low-level detail → extract the detail.
  5. NAMING: Does each function/variable name reveal intent without needing surrounding context? If not → rename to be self-documenting.
  6. PARAMETERS: Is the parameter count under the threshold from the loaded doc (4 default)? If not → group parameters into an object.
  7. PRIMITIVE OBSESSION: Would a string/number/boolean be clearer as a named type? If so → introduce a parameter object or typed wrapper.
  8. ERROR HANDLING: Does every fail-able operation have explicit handling with an actionable message? Is it handled at the right level?

Project-specific checks: if the loaded doc (from Config Resolution) contains a Validation Checklist section (§10 from the clean-code-refiner template), apply those checks as additional project-specific validation after the checklist above.

All checks pass → state "Passes clean-code. [next step]."

Active Anti-Pattern Scan

After the checklist, scan for each of these. Any box you can check → fix before presenting.

  • God Function: a function exceeds ~30 lines doing multiple things; describing it requires "and" → extract focused functions.
  • Deep Nesting: three or more levels of indentation → flatten with early returns / guard clauses.
  • Cryptic Naming: variables like d, tmp2, processData → rename to reveal intent.
  • Long Parameter Lists: five or more parameters → group into an object or split the function.
  • Premature Abstraction: a utility extracted from only two similar blocks → inline it until the Rule of Three (third instance with the same reason to change).
  • Swallowed Errors: empty catch blocks, generic "something went wrong" messages, silent null returns → handle explicitly.
  • Comments as Deodorant: a comment explains convoluted code instead of the code being fixed → rename to self-document; keep only "why" comments, remove "what" comments.
  • Hidden Side Effects: a function named getX also writes a cache or sends notifications → rename or separate the concern.
  • Dead Code: commented-out blocks, unused imports, unreachable branches → delete them (version control preserves history).
  • Untestable Logic: side effects tangled with business logic; unit testing requires mocking I/O → push side effects to the boundary, extract pure functions, inject dependencies.

Ambiguity Signals

Multiple valid outcomes exist. Present the options rather than silently choosing. If framework:collaborative-judgment is loaded, use its presentation format. See ./references/defaults.md for resolution guidance on each signal below.

  • Single Responsibility: two tightly-coupled sequential operations may be one responsibility (a pipeline), not two. The "and" test catches true violations AND false positives.
  • Function Size: near-threshold size (20–30 lines) with one clear purpose -- extraction may create five unclear smaller functions. Present the tradeoff.
  • DRY vs Premature Abstraction: two identical blocks may serve different purposes and diverge independently. Until a third instance with the same reason to change appears, this is genuinely ambiguous.
  • Error Handling Strategy: exception vs Result type vs error codes depends on language idiom and team convention, not on universal rules.

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.