AgentSkillsCN

clean-code

务实的编码规范——简洁明了,直击要害,杜绝过度工程化。

SKILL.md
--- frontmatter
name: clean-code
description: Pragmatic coding standards - concise, direct, no over-engineering
priority: CRITICAL

Clean Code Standards

Be concise, direct, and solution-focused.


Core Principles

PrincipleRule
SRPSingle Responsibility - one thing per function/class
DRYDon't Repeat Yourself
KISSKeep It Simple
YAGNIYou Aren't Gonna Need It

Naming

ElementConventionExample
VariablesReveal intentuserCount not n
FunctionsVerb + noungetUserById()
BooleansQuestion formisActive, hasPermission
ConstantsSCREAMING_SNAKEMAX_RETRY_COUNT

Functions

RuleGuideline
SmallMax 20 lines
One ThingSingle purpose
Few ArgsMax 3 parameters
No Side EffectsDon't mutate inputs

Code Structure

PatternApply
Guard ClausesEarly returns
Flat > NestedMax 2 levels
CompositionSmall functions together

Anti-Patterns

❌ Don't✅ Do
Comment every lineSelf-documenting names
Helper for one-linerInline the code
Factory for 2 objectsDirect instantiation
Deep nestingGuard clauses
Magic numbersNamed constants

Before Editing

QuestionWhy
What imports this file?They might break
What tests cover this?Tests might fail
Is this shared?Multiple places affected

Self-Check

CheckQuestion
✅ Goal met?Did exactly what was asked?
✅ Code works?Verified the change?
✅ No errors?Lint and types pass?