clean-code
clean-code, the rules for readable code. Use when writing code, editing or refactoring code, or when the user names the clean-code skill. Covers names, functions, control flow, classes and vertical layout, and delegates comments to code-comments and documentation to project-docs.
- License 许可
- MIT
- 最近更新
- 2026-11-11
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- clean-code
- description
- clean-code, the rules for readable code. Use when writing code, editing or refactoring code, or when the user names the clean-code skill. Covers names, functions, control flow, classes and vertical layout, and delegates comments to code-comments and documentation to project-docs.
02 资源文件 19
- 参考文档formatting/coverage.md4.7 KB
- 参考文档formatting/formatting.md2.0 KB
- 其他formatting/java/checkstyle.xml1.4 KB
- 其他formatting/kotlin/.editorconfig2.3 KB
- 参考文档formatting/kotlin/detekt.yml328 B
- 其他formatting/python/ruff.toml1001 B
- 其他formatting/swift/.swift-format8.8 KB
- 参考文档formatting/swift/.swiftlint.yml305 B
- 其他formatting/typescript/.oxfmtrc.jsonc859 B
- 其他formatting/typescript/.oxlintrc.jsonc3.3 KB
- 参考文档languages/java.md5.6 KB
- 参考文档languages/kotlin.md5.3 KB
- 参考文档languages/python.md4.6 KB
- 参考文档languages/swift.md4.7 KB
- 参考文档languages/typescript.md5.7 KB
- 参考文档references/classes.md5.8 KB
- 参考文档references/control-flow.md4.8 KB
- 参考文档references/functions.md4.5 KB
- 参考文档references/naming.md2.6 KB
03 SKILL.md 正文
Rules for every symbol you write or touch. Names carry the meaning, functions do one thing at one level of abstraction, control flow stays flat, classes stay focused, and a comment appears only where the code cannot speak.
Steps
- Pick the language guide. Map the file extension and read the guide before writing:
.swiftlanguages/swift.md,.kt.ktslanguages/kotlin.md,.javalanguages/java.md,.ts.tsx.js.jsxlanguages/typescript.md,.pylanguages/python.md. For any other language apply the rules below with that language's own idioms. Where a language guide and a reference underreferences/differ, the language guide wins. - Read the neighbouring code. Before naming anything, read the file and its siblings and adopt their verbs, nouns and error idiom. Consistency beats preference: when the project says
fetch, the new function saysfetch. A misleading or domain-wrong existing name is the one exception, see Renaming. - Name every touched symbol. Nouns for variables, properties and classes. Verbs for functions and methods. A yes or no question for booleans. Specific over generic, so
createUserinstead ofcreateandproductinstead ofitem. Full words, no slang, no abbreviation the reader must decode, no adjective the context already supplies. Details in references/naming.md. - Shape every touched function. One thing: every statement one level of abstraction below what the name promises, none mixed with lower detail. Few parameters, related ones grouped in one container. Every side effect implied by the name or the calling context. Each piece of logic in one place. Extract when a block is a coherent sub-task or needs more interpretation than its surroundings, and stop extracting when the split only renames, forces scrolling, or has no free name. Explicit over compact: the longer form wins the moment the reader has to decode the shorter one, the language guide lists the constructs that tempt. Details in references/functions.md, laziness-protocol and minimize-reader-load.
- Flatten control flow. Guards at the top, failing fast. Positive checks, except where one negative check replaces a growing list of positives. Extract a nested control structure into its own function. Replace repeated type checks with polymorphism behind a factory. Signal failure through a structured error contract the language or the project enforces, never through a code, a flag or a message object returned beside a normal value. Details in references/control-flow.md and model-the-domain.
- Keep classes focused. Each class is a real object (private data, public behaviour) or a data container (public data, no behaviour beyond read-only derived values), never both. One responsibility, high cohesion. Real objects follow the Law of Demeter and are told, not asked. Extension by adding a subclass or implementation, not by editing a growing switch. Details in references/classes.md, boundary-discipline and type-system-discipline.
- Order the file. Callers above callees, public API above private helpers. A file that holds unrelated things is split. Line length and indentation belong to the project formatter. Details in formatting/formatting.md.
- Keep tests honest. Every test the change writes or touches calls the code the way its users do and asserts the result they observe against a literal expected value. Details in test-behavior-not-implementation.
- Apply code-comments. Every comment in the touched symbol follows the code-comments skill. Nothing else about comments lives here.
- Apply project-docs. When the change alters a behaviour, a command, an option or a path that the project's documentation describes, bring that documentation in line with the project-docs skill. Nothing else about documentation lives here.
Done when every touched symbol has a descriptive name consistent with the project, every touched function does one thing at one level of abstraction with no unexpected side effect and no expression the reader must decode, no nested control structure remains that a guard or an extraction would flatten, every touched class is a real object or a data container with one responsibility, the file reads top down, every touched test calls the code the way its users do and asserts the result they observe against a literal expected value, the comments pass code-comments, and the documentation still matches the code.
Renaming
Read the existing names with the domain in mind. A name that describes something other than what the symbol does or holds, or uses the wrong domain term, is not adopted. Rename it when you have checked every dependency and the change is safe: all call sites, overrides, serialized keys, reflection and string references. For a rename that spans many files or touches a public API, dispatch a sub-agent to trace the dependencies first. When the risk stays unclear, keep the name, and name the better one and the reason in your reply. Never block on a question for a rename.
Scope
The rules apply to the symbols you write or change. Surrounding code stays as it is, so the diff shows the intended change. A file you touch only to add a call keeps its shape.
04 同仓库更多 Skills
why
Use for 'why does X work this way', 'why we picked Y', design rationale, regressions, postmortems, or data-backed thresholds. Discovers available MCPs and queries each evidence category (source control, issue tracker, long-form docs, real-time chat, infrastructure observability, error tracking, product analytics warehouse) in parallel, then returns a cited read on decisions and tradeoffs. Use how for runtime behavior.
tdd
Use only when the user explicitly asks for TDD, a failing test, or a regression test, OR when the bug has an obvious cheap local test target. Skip when the test path is unclear, expensive, integration-heavy, or not requested.
swarm
Fan out N parallel workers, drain them, and return one report. Use for /swarm, 'swarm this', or parallel coverage, races, gauntlets, and exploration.
show-me-your-work
Keep a reviewable decision trail for long-running or unattended work: a TSV log with one row per decision (what, why, evidence, result). Local by default; commit it when a reviewer needs the trail to trust the result. Use for /show-me-your-work, autonomous or multi-phase runs, or work a human reviews after stepping away.
interrogate
Use for "interrogate", "adversarial review", "multi-model review", "challenge this", "stress test this code", "find blind spots", or "tear this apart". Multiple LLM reviewers challenge changes from independent angles.
how
Use for "how does X work", code walkthroughs before changing something, and placement / ownership / layering questions ("where should this live", "which package owns this", "is this the right layer"). Explains subsystem architecture, runtime flow, onboarding mental models. Use why for motivation.