quality-common

v2026.09.24

Universal code quality principles applicable to all languages. Covers Clean Code, SOLID, complexity metrics, and quality standards. USE WHEN: user mentions "clean code", "SOLID", "code smells", "refactoring", "complexity", asks about "cyclomatic complexity", "cognitive complexity", "code review", "maintainability" DO NOT USE FOR: language-specific linting - use ESLint/Biome skills, security - use OWASP skills, testing - use testing skills

GitHub
安装命令
npx skhub add claude-dev-suite/quality-common
Markdown
SKILL.md

Universal Code Quality Principles

When NOT to Use This Skill

  • Language-specific rules - Use TypeScript/Java/Python skills for syntax/idioms
  • Security issues - Use owasp-top-10 for vulnerabilities
  • Testing strategies - Use Vitest/Playwright skills for test quality
  • Linting configuration - Use ESLint/Biome skills for tool setup

Deep Knowledge: Use mcp__documentation__fetch_docs with technology: clean-code for comprehensive documentation.

Authoritative References

PrincipleSourceLink
Clean CodeRobert C. MartinClean Code Book
SOLIDRobert C. MartinSOLID Principles
RefactoringMartin FowlerRefactoring Catalog
Cognitive ComplexitySonarSourceWhitepaper (PDF)

Clean Code Principles

Naming

  • Intention-revealing: Names should explain purpose
  • Pronounceable: Avoid abbreviations
  • Searchable: Avoid single letters except loops

Functions

  • Small: 20 lines max, ideally < 10
  • Single purpose: Do one thing well
  • Few arguments: 0-2 ideal, 3 max

Comments

  • Code should be self-documenting
  • Comments explain "why", not "what"
  • Avoid redundant comments

SOLID Principles

PrincipleDescriptionViolation Sign
Single ResponsibilityOne reason to changeClass does too much
Open/ClosedOpen for extension, closed for modificationSwitch statements on type
Liskov SubstitutionSubtypes must be substitutableOverride throws exception
Interface SegregationMany specific interfacesUnused interface methods
Dependency InversionDepend on abstractionsnew in business logic

Code Metrics & Thresholds

Complexity Metrics

MetricDescriptionThresholdTool
Cyclomatic ComplexityNumber of independent paths< 10SonarQube, ESLint
Cognitive ComplexityHow hard to understand< 15SonarQube
Lines per FunctionFunction length< 30All linters
ParametersFunction arguments< 4All linters
Nesting DepthIf/loop nesting< 4SonarQube

Quality Gates (SonarQube Standard)

MetricConditionTarget
Coverageon new code> 80%
Duplicationson new code< 3%
Maintainability RatingoverallA
Reliability RatingoverallA
Security RatingoverallA

Code Smells Categories

Bloaters

  • Long Method
  • Large Class
  • Long Parameter List
  • Data Clumps

Object-Orientation Abusers

  • Switch Statements
  • Refused Bequest
  • Alternative Classes with Different Interfaces

Change Preventers

  • Divergent Change
  • Shotgun Surgery
  • Parallel Inheritance Hierarchies

Dispensables

  • Dead Code
  • Duplicate Code
  • Lazy Class
  • Speculative Generality

Couplers

  • Feature Envy
  • Inappropriate Intimacy
  • Message Chains

Refactoring Patterns

SmellRefactoringDescription
Long MethodExtract MethodBreak into smaller functions
Duplicate CodeExtract Method/ClassCreate reusable unit
Long Parameter ListIntroduce Parameter ObjectGroup related params
Switch on TypeReplace with PolymorphismUse strategy pattern
Feature EnvyMove MethodPut behavior with data
God ClassExtract ClassSplit responsibilities

Full Catalog: https://refactoring.com/catalog/


Quick Checklist

## Code Review Checklist

### Readability
- [ ] Clear, intention-revealing names
- [ ] Functions are small and focused
- [ ] No magic numbers/strings
- [ ] Appropriate abstraction level

### Maintainability
- [ ] Single Responsibility followed
- [ ] No code duplication (DRY)
- [ ] Dependencies injected, not created
- [ ] Easy to test in isolation

### Reliability
- [ ] Edge cases handled
- [ ] Errors handled appropriately
- [ ] No null pointer risks
- [ ] Resources properly closed

### Performance
- [ ] No N+1 queries
- [ ] Appropriate data structures
- [ ] No premature optimization
- [ ] Caching where appropriate

Anti-Patterns

Anti-PatternWhy It's BadCorrect Approach
God Class (1000+ lines)Violates SRP, hard to testSplit into focused classes
Magic numbers everywhereUnclear meaning, hard to changeUse named constants
Deep nesting (5+ levels)Hard to understandExtract methods, early returns
Long parameter lists (6+ params)Hard to remember orderUse parameter objects/builders
Copy-paste programmingDuplication, maintenance nightmareExtract shared logic to functions
No error handlingSilent failuresExplicit error handling with logging

Quick Troubleshooting

IssueLikely CauseSolution
Function has complexity > 20Too many branches/loopsExtract sub-functions, use strategy pattern
Class over 500 linesMultiple responsibilitiesApply SRP, split into multiple classes
Tests hard to writeTight coupling, no DIUse dependency injection
Same code in 3+ placesNo abstractionExtract to shared function/class
Function takes 10+ parametersPoor abstractionCreate parameter object or builder
Code hard to understandPoor naming, no abstractionRefactor with intention-revealing names

Related Skills

  • Language-specific rules: languages/typescript, languages/java, languages/python
  • Security: security/owasp-top-10
  • Design Patterns: best-practices/design-patterns
发现
标签

此技能尚未发布标签。

版本
最新版本元数据

版本

v2026.09.24

发布时间

2026年9月24日

分类

未分类

许可证

MIT

源路径

skills/quality/common

默认分支

main

最新提交

9496306

Tree SHA

fe4e2f1