AgentSkillsCN

Clean Code

秉持务实的 AI 编码规范,力求代码简洁、直白、聚焦解决方案。严格执行单一职责原则(SRP)、DRY 原则、KISS 原则、YAGNI 原则,并辅以严格的验证检查。

SKILL.md
--- frontmatter
name: Clean Code
description: Pragmatic AI coding standards for keeping code concise, direct, and solution-focused. Enforces SRP, DRY, KISS, YAGNI, and strict verification checks.
source: sickn33/antigravity-awesome-skills/clean-code

Clean Code - Pragmatic AI Coding Standards

CRITICAL SKILL - Be concise, direct, and solution-focused.

Core Principles

PrincipleRule
SRPSingle Responsibility - each function/class does ONE thing
DRYDon't Repeat Yourself - extract duplicates, reuse
KISSKeep It Simple - simplest solution that works
YAGNIYou Aren't Gonna Need It - don't build unused features
Boy ScoutLeave code cleaner than you found it

Naming Rules

ElementConvention
VariablesReveal intent: userCount not n
FunctionsVerb + noun: getUserById() not user()
BooleansQuestion form: isActive, hasPermission, canEdit
ConstantsSCREAMING_SNAKE: MAX_RETRY_COUNT

Function Rules

RuleDescription
SmallMax 20 lines, ideally 5-10
One ThingDoes one thing, does it well
One LevelOne level of abstraction per function
Few ArgsMax 3 arguments, prefer 0-2
No Side EffectsDon't mutate inputs unexpectedly

Code Structure

PatternApply
Guard ClausesEarly returns for edge cases
Flat > NestedAvoid deep nesting (max 2 levels)
CompositionSmall functions composed together
ColocationKeep related code close

AI Coding Style

SituationAction
User asks for featureWrite it directly
User reports bugFix it, don't explain
No clear requirementAsk, don't assume

Anti-Patterns (DON'T)

❌ Pattern✅ Fix
Comment every lineDelete obvious comments
Helper for one-linerInline the code
Factory for 2 objectsDirect instantiation
utils.ts with 1 functionPut code where used
"First we import..."Just write code
Deep nestingGuard clauses
Magic numbersNamed constants
God functionsSplit by responsibility

🔴 Before Editing ANY File (THINK FIRST!)

Before changing a file, ask yourself:

  1. What imports this file? (They might break)
  2. What does this file import? (Interface changes)
  3. What tests cover this? (Tests might fail)
  4. Is this a shared component? (Multiple places affected)

🔴 Rule: Edit the file + all dependent files in the SAME task. 🔴 Never leave broken imports or missing updates.

🔴 Self-Check Before Completing (MANDATORY)

Before saying "task complete", verify:

CheckQuestion
Goal met?Did I do exactly what user asked?
Files edited?Did I modify all necessary files?
Code works?Did I test/verify the change?
No errors?Lint and TypeScript pass?
Nothing forgotten?Any edge cases missed?