agentleFS
DavidBeliczaDavidBelicza/Magento-MCP-Server/.agents/skills/clean-code-pass/SKILL.md

clean-code-pass

Skill1 starsChanged 5 months agoMITView on GitHub

Use when asked to clean up, refactor, or improve code quality without changing behavior — making dependencies mockable for unit testing, flattening nested control flow inside loops, and removing comments in favor of self-documenting code. Offers to commit the result afterwards.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Keep the port thin: it wraps the raw call.

    line 23
  2. Very specific:

    Do not wrap a collaborator that is already injected.

    line 42
  3. Very specific:

    Delete // and inline comments.

    line 71
  4. Very specific:

    Keep a / */ doc block only when it carries type information the signature cannot.

    line 74
  5. Very specific:

    Follow the rest of the project conventions in AGENTS.md (dash-case filenames, early returns, match/switch over long if-chains, enums over …

    line 77
  6. Distinctive:

    Run the project checks and confirm they pass before offering to commit:

    line 83
  7. Distinctive:

    Do not add test files unless explicitly requested.

    line 91

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “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 Pass

A behavior-preserving cleanup pass with three checks, then verification, then an offer to commit. Apply only what is relevant to the files in scope; do not rewrite working code that already follows these rules.

1. Make dependencies mockable without implementing classes

Inject collaborators so a unit test can supply a fake, but do not introduce a class hierarchy or a DI framework to do it. Use a plain function-bag port.

  • Define a port type: an object whose properties are the functions the module calls (the side-effecting ones — filesystem, network, clock, random).
  • Provide a default implementation bound to the real dependency.
  • Accept the port as an optional last parameter defaulting to the real implementation, so production callers stay unchanged and tests pass a plain object literal.
  • Keep the port thin: it wraps the raw call. Error-handling and branching stay in the module so they are testable.
export type FileSystemPort = {
  readFile: (path: string) => Promise<string>;
  statIsFile: (path: string) => Promise<boolean>;
};

export const nodeFileSystem: FileSystemPort = {
  readFile: (path) => readFile(path, "utf8"),
  statIsFile: async (path) => (await stat(path)).isFile()
};

export async function process(path: string, fs: FileSystemPort = nodeFileSystem) {
  /* ... */
}

Do not wrap a collaborator that is already injected. If a function already receives a driver, client, or pool as an argument (e.g. a Neo4j Driver), it is already mockable — leave it alone.

2. Flatten functions — no nested ifs inside a loop

A loop body should not contain an if whose body contains another if. Flatten with these moves, in order of preference:

  • Guard clauses. Replace an if (ok) { work } wrapper with if (!ok) continue; then the work at the top level.
  • Extract per-iteration work into a named helper that returns a value or null; the loop body becomes a single call plus one guard.
  • Build collections functionally. Replace an accumulating loop with map / flatMap / filter, using a small mapper that returns the item or null and a type-guard filter ((x): x is T => x !== null).
  • Classify, then branch flat. Replace a nested if/else-if selection with a helper that returns a discriminated category, then a single flat if/else-if chain (or a switch) over that category.

The goal is one level of decision per scope. A loop containing a loop is fine; a loop containing nested conditionals is what this removes.

3. Remove comments — let the code describe itself

This project forbids source comments; ESLint enforces it. The only allowed comment is a /** */ doc block, and only for type information a native type cannot express (generics, array shapes).

  • Delete // and inline comments. If a comment was explaining what code does, that is a signal to rename a variable or extract a well-named helper, not to keep the comment.
  • Keep a /** */ doc block only when it carries type information the signature cannot. If a doc block is present, document every such parameter and the return so it is not partial.
  • Follow the rest of the project conventions in AGENTS.md (dash-case filenames, early returns, match/switch over long if-chains, enums over magic strings).

4. Verify

Run the project checks and confirm they pass before offering to commit:

npm run typecheck
npm run lint
npm test

Do not add test files unless explicitly requested; the mockability change exists so tests can be written later.

5. Offer to commit

Once the checks pass, offer to run the git-commit-and-push skill to commit the cleanup. Do not commit automatically — propose it and let the user decide.

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.