‹ 首页

clean-code

@dragoscirjan · 收录于 1 周前 · 上游提交 1 个月前

Clean code principles, SOLID, design patterns, readability, error handling, and universal quality tooling. Load when writing or reviewing code.

适合你,如果你在写或审查代码时希望遵循最佳实践

/ 通过 npx 安装 校验哈希
npx oh-my-skill add dragoscirjan/opencode-config/clean-code
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- dragoscirjan/opencode-config/clean-code
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify dragoscirjan/opencode-config/clean-code
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
0GitHub stars
~711上下文体积 · 单文件
索引托管

怎么用

商店整理自技能原文 · 版本 f561928 · 表述以原文为准
它做什么

Claude 会按照整洁代码原则、SOLID 原则和设计模式来编写或审查代码,注重可读性、错误处理和代码质量。

什么时候触发

当你要求编写或审查代码时,Claude 会应用这些原则。

装好后可以这样说
Claude 会应用整洁代码原则进行审查。
Claude 会按 SOLID 原则重构。
Claude 会检查 DRY 和错误处理。
技能原文 SKILL.md作者撰写 · MIT · f561928

Clean Code & Design Principles

Readability
  • Code should read like well-written prose — clear intent at every level
  • Use meaningful, descriptive names for variables, functions, classes, and modules
  • Keep functions short and focused — each function does one thing well
  • Avoid deep nesting — extract early returns, guard clauses, and helper functions
  • Write meaningful comments for _why_, not _what_ — the code itself should explain the what
Clean Code Principles
  • KISS — Keep It Simple. Prefer the simplest solution that works correctly.
  • DRY — Don't Repeat Yourself. Extract shared logic, but don't over-abstract prematurely.
  • YAGNI — You Aren't Gonna Need It. Don't add functionality "just in case."
  • Boy Scout Rule — Leave the code cleaner than you found it.
  • Fail Fast — Validate inputs early, surface errors immediately.
  • Least Surprise — Code should behave as the reader expects.
SOLID Principles
  • Single Responsibility — A class/module should have one reason to change
  • Open/Closed — Open for extension, closed for modification
  • Liskov Substitution — Subtypes must be substitutable for their base types
  • Interface Segregation — Prefer small, focused interfaces over large ones
  • Dependency Inversion — Depend on abstractions, not concretions
Design Patterns
  • Apply design patterns where they solve a real problem — not for their own sake
  • Favor composition over inheritance
  • Use dependency injection for testability and flexibility
  • Prefer immutable data structures when practical
  • Use the Strategy pattern for interchangeable behaviors, Observer for event-driven logic, Factory for complex object creation — but only when the pattern genuinely simplifies the code
Error Handling
  • Handle errors properly — no swallowed exceptions
  • Use typed/specific errors over generic ones
  • Provide meaningful error messages with context
  • Clean up resources in error paths (finally, defer, using, etc.)
Universal Quality Tools

Apply these cross-language tools on every project:

| Tool | Purpose | Reference | | ------------------------- | ---------------------------------------------- | ----------------------------------- | | .editorconfig | Cross-editor indent, charset, EOL consistency | https://editorconfig.org | | jscpd | Copy-paste detection (all languages) | https://github.com/kucherenko/jscpd | | Semgrep | Multi-language static analysis, custom rules | https://semgrep.dev | | SonarQube / SonarLint | Code quality + security dashboard | https://www.sonarsource.com | | MegaLinter | Meta-linter for CI (orchestrates 100+ linters) | https://megalinter.io | | pre-commit | Git hook framework for linters/formatters | https://pre-commit.com | | Trunk | Auto-detect and run linters/formatters | https://trunk.io | | Taskfile | Task runner for build/test/lint/format | https://taskfile.dev | | commitlint | Commit message convention enforcement | https://commitlint.js.org |

  • Every project must have an .editorconfig at the root
  • Use run-quality-checks to enforce duplicated code checks to catch duplicated code blocks
  • Use run-quality-checks to enforce linting/formatting before commit
  • Use Taskfile for consistent task lint, task format, task test, task validate commands
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。