Typescript Clean Code

bmad-labs/skills/skills/typescript-clean-code

作者 bmad-labsf2e09b317c6f无许可证16 个星标收录于 2026年10月8日更新于 2026年10月8日仓库3周前更新

Clean Code for TypeScript — code smell catalogs (Martin's per-line heuristics, Fowler's change-shape smells, TypeScript-native type smells), a linter-first detection policy, and step-by-step review, refactoring, TDD, and estimation workflows. Use when the user: - Writes, reviews, or refactors TypeScript/JavaScript code, or asks whether code is clean, maintainable, or well-designed - Names a smell — Shotgun Surgery, Feature Envy, Data Clumps, Long Method, Divergent Change, Duplicated Code, Large Class, Long Parameter List, Primitive Obsession, Message Chains, Dead Code, Speculative Generality, god class, copy-paste, stringly typed, premature abstraction - Asks about TypeScript type hygiene — `any` leakage, `as` assertions, non-null `!`, discriminated unions, exhaustiveness, strict flags, branded types - Asks what to enforce with lint or tsconfig versus what needs judgment, or names knip, jscpd, dependency-cruiser, typescript-eslint, type-coverage - Runs TDD, fixes a bug with test coverage, or plans test strat

AI 生成的概览

借助分层代码坏味道目录与分步工作流,指导 TypeScript 代码审查、重构、TDD 与估算。

功能
为 TypeScript 和 JavaScript 提供整洁代码参考集:逐行启发式规则、Fowler 的十二种变更形态坏味道、TypeScript 类型坏味道,以及以 linter 优先的检测策略。它提供代码审查、拉取请求审查、重构、TDD、新功能、缺陷修复、测试策略、估算和截止时间协商的分步工作流,每个工作流都配有步骤文件和报告模板。产出为审查发现、重构计划和报告,而非可执行代码。
适用场景
适用于编写、审查或重构 TypeScript 或 JavaScript 代码,或判断代码是否整洁、可维护时。也适合指出具体坏味道、讨论 TypeScript 类型卫生、决定用 lint 或 tsconfig 强制什么,以及规划测试或任务估算。
运行要求
仅为说明文档与参考文件,不附带脚本。代理无需安装包、凭据或网络访问,但工作流可能引用 linter、type-coverage 等外部工具。

Clean Code

The twelve change-shape smells

Shotgun Surgery · Feature Envy · Data Clumps · Long Method · Divergent Change · Duplicated Code · Large Class · Long Parameter List · Primitive Obsession · Message Chains · Dead Code · Speculative Generality

You know each one and its refactoring. The value is the checklist, not the definitions — without the names a diff "looks fine"; with them you find the shape. Run all twelve against any change you review or write.

The smell catalog has four layers

Each examines a different unit, so each sees what the others miss.

LoadUnitFor
references/smells/tooling.mdthe repositoryFirst, in every review. Which smells a linter decides, so those become one "wire this into CI" finding instead of twenty hand-written ones
references/smells/rules.mda line, a functionPer-line heuristics (C/E/F/G/N/T), plus the review posture and severity vocabulary that govern all four layers
references/smells/fowler.mda modificationThe twelve above — detection question, TypeScript remedy, and when NOT to fix for each
references/smells/typescript.mda typeTS1-TS10: any leakage, assertion versus validation, exhaustiveness, strictness flags, branded types

A diff can satisfy every rule in rules.md and still be badly shaped — that is what fowler.md is for. Reviewing a change means all four.

Review posture

Three rules that change output more than any catalog entry. Full text in references/smells/rules.md → "Review posture".

  1. Approve when the change improves code health, not when it is perfect. There is no perfect code, only better code.
  2. A correct finding nobody acts on is a false positive. Scan broadly, report selectively — three actionable findings beat twenty true ones.
  3. Mark polish as ignorable. Conventional Comments labels — issue, suggestion, nitpick, question, praise — with (blocking) / (non-blocking). An author who cannot tell which comments are optional treats all of them as mandatory, or none of them.

A review is done when all four layers have run, every surviving finding carries a label and (for an issue) a fix, and the report states how many findings were cut as unlikely to be acted on.

Contested rules

Three rules in these references are positions with live counter-arguments, marked contested where they appear. Present both sides and prefer the author's demonstrated reasoning over the number:

  • Function length — references/functions/rules.md Rule 1. Detect by "can I name each section?"; the "2-5 lines" figure over-extracts when applied literally.
  • Comments — references/comments/rules.md. Keep rationale, invariants, and non-obvious why; delete restatement and stale comments.
  • G23 polymorphism — references/smells/rules.md. An exhaustive switch over a discriminated union is idiomatic TypeScript, not a smell.

Workflows

Load the workflow.md, then its step files in order. Each step names the references it needs and updates stepsCompleted in the output document's frontmatter, so a compacted context resumes from the last completed step via step-01b-continue.md.

WorkflowFor
workflows/code-review/workflow.mdReviewing code for quality
workflows/pr-review/workflow.mdReviewing pull requests
workflows/refactoring/workflow.mdSafe refactoring with tests (step 3 sweeps all twelve; steps 5-8 loop)
workflows/tdd.mdTest-driven development cycle
workflows/new-feature.mdBuilding new functionality
workflows/bug-fix.mdFixing bugs properly
workflows/test-strategy.mdPlanning test coverage
workflows/estimation.mdEstimating tasks (PERT)
workflows/deadline-negotiation.mdHandling unrealistic deadlines

References

references/<topic>/ holds rules.md (the rules), examples.md (curated TypeScript bad/good pairs — prefer these over inventing your own), and knowledge.md (concepts).

Code quality: naming · functions · classes · comments · error-handling · unit-tests · formatting · smells

Professional practice: professionalism · saying-no · commitment · coding-practices · tdd · practicing · acceptance-testing · testing-strategies · time-management · estimation · pressure · collaboration

Load the topic's rules.md before advising on it, and cite the rule you applied — the design problem it names, not the metric that pointed at it. Where a reference contradicts your general knowledge, the reference wins: it carries this skill's TypeScript adaptations and thresholds.

guidelines.md maps symptom → reference file and task → workflow.

来源与署名

来源:bmad-labs/skills位于skills/typescript-clean-code提交f2e09b3

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架