clean-code-principles by asyrafhussin/agent-skills
npx skills add https://github.com/asyrafhussin/agent-skills --skill clean-code-principles基础的软件设计原则、SOLID、设计模式以及整洁代码实践。编写可维护、可扩展软件的语言无关指南。
在以下情况时参考这些指南:
| 优先级 | 类别 | 影响 | 前缀 |
|---|---|---|---|
| 1 | SOLID 原则 | 关键 | solid- |
| 2 | 核心原则 | 关键 | core- |
| 3 | 设计模式 | 高 | pattern- |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 4 | 代码组织 | 高 | org- |
| 5 | 命名与可读性 | 中 | name- |
| 6 | 函数与方法 | 中 | func- |
| 7 | 注释与文档 | 低 | doc- |
solid-srp - 单一职责原则solid-ocp - 开闭原则solid-lsp - 里氏替换原则solid-isp - 接口隔离原则solid-dip - 依赖倒置原则core-dry - 不要重复自己core-kiss - 保持简单,傻瓜core-yagni - 你不会需要它core-separation-of-concerns - 关注点分离core-composition-over-inheritance - 优先使用组合而非继承core-law-of-demeter - 最少知识原则core-fail-fast - 快速失败core-encapsulation - 封装pattern-factory - 用于对象创建的工厂模式pattern-strategy - 用于算法的策略模式pattern-repository - 用于数据访问的仓储模式pattern-decorator - 用于行为扩展的装饰器模式pattern-observer - 用于事件处理的观察者模式pattern-adapter - 用于接口转换的适配器模式pattern-facade - 用于简化接口的外观模式pattern-dependency-injection - 用于松耦合的依赖注入org-feature-folders - 按功能而非层级组织org-module-boundaries - 清晰的模块边界org-layered-architecture - 正确的层级分离org-package-cohesion - 相关代码放在一起org-circular-dependencies - 避免循环导入name-meaningful - 使用能揭示意图的名称name-consistent - 一致的命名约定name-searchable - 避免魔法数字/字符串name-avoid-encodings - 不要使用匈牙利命名法name-domain-language - 使用领域术语func-small - 保持函数短小func-single-purpose - 只做一件事func-few-arguments - 限制参数数量func-no-side-effects - 最小化副作用func-command-query - 分离命令与查询doc-self-documenting - 代码应能自我解释doc-why-not-what - 解释原因,而非内容doc-avoid-noise - 避免冗余注释doc-api-docs - 为公共 API 编写文档关于详细示例和解释,请参阅规则文件:
| 原则 | 定义 |
|---|---|
| S 单一职责 | 一个类应该只有一个引起变化的原因 |
| O 开闭 | 对扩展开放,对修改关闭 |
| L 里氏替换 | 子类型必须能够替换其基类型 |
| I 接口隔离 | 不应强迫客户端依赖它们不使用的接口 |
| D 依赖倒置 | 依赖抽象,而非具体实现 |
| 原则 | 定义 |
|---|---|
| DRY | 不要重复自己 - 单一事实来源 |
| KISS | 保持简单 - 避免过度设计 |
| YAGNI | 你不会需要它 - 只构建所需的功能 |
// 单一职责 - 一个类,一个职责
class UserService {
constructor(
private validator: UserValidator,
private repository: UserRepository,
) {}
createUser(data) {
this.validator.validate(data);
return this.repository.create(data);
}
}
// 依赖倒置 - 依赖抽象
interface Repository<T> {
find(id: string): Promise<T | null>;
save(entity: T): Promise<T>;
}
class OrderService {
constructor(private repository: Repository<Order>) {}
}
// DRY - 单一事实来源
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const isValidEmail = (email: string) => EMAIL_REGEX.test(email);
// 使用有意义的名称而非魔法数字
const MINIMUM_AGE = 18;
if (user.age >= MINIMUM_AGE) { }
审计代码时,请按以下格式输出发现的问题:
file:line - [principle] Description of issue
示例:
src/services/UserService.ts:15 - [solid-srp] Class handles validation, persistence, and notifications
src/utils/helpers.ts:42 - [core-dry] Email validation duplicated from validators/email.ts
src/models/Order.ts:28 - [name-meaningful] Variable 'x' should describe its purpose
阅读单独的规则文件以获取详细解释:
rules/solid-srp-class.md
rules/core-dry.md
rules/pattern-repository.md
此技能建立在成熟的软件工程原则之上:
版本: 1.0.2 状态: 活跃 覆盖范围: 3 个已实现类别(SOLID、核心原则、设计模式)中的 23 条规则;4 个计划中 最后更新: 2026-03-07
每周安装量
339
代码仓库
GitHub 星标数
18
首次出现
2026年1月21日
安全审计
安装于
codex285
opencode280
gemini-cli278
github-copilot260
cursor229
claude-code221
Fundamental software design principles, SOLID, design patterns, and clean code practices. Language-agnostic guidelines for writing maintainable, scalable software.
Reference these guidelines when:
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | SOLID Principles | CRITICAL | solid- |
| 2 | Core Principles | CRITICAL | core- |
| 3 | Design Patterns | HIGH | pattern- |
| 4 | Code Organization | HIGH | org- |
| 5 | Naming & Readability | MEDIUM | name- |
| 6 | Functions & Methods | MEDIUM | func- |
| 7 | Comments & Documentation | LOW | doc- |
solid-srp - Single Responsibility Principlesolid-ocp - Open/Closed Principlesolid-lsp - Liskov Substitution Principlesolid-isp - Interface Segregation Principlesolid-dip - Dependency Inversion Principlecore-dry - Don't Repeat Yourselfcore-kiss - Keep It Simple, Stupidcore-yagni - You Aren't Gonna Need Itcore-separation-of-concerns - Separate different responsibilitiescore-composition-over-inheritance - Favor compositioncore-law-of-demeter - Principle of least knowledgecore-fail-fast - Detect and report errors earlycore-encapsulation - Hide implementation detailspattern-factory - Factory pattern for object creationpattern-strategy - Strategy pattern for algorithmspattern-repository - Repository pattern for data accesspattern-decorator - Decorator pattern for behavior extensionpattern-observer - Observer pattern for event handlingpattern-adapter - Adapter pattern for interface conversionpattern-facade - Facade pattern for simplified interfacespattern-dependency-injection - DI for loose couplingorg-feature-folders - Organize by feature, not layerorg-module-boundaries - Clear module boundariesorg-layered-architecture - Proper layer separationorg-package-cohesion - Related code togetherorg-circular-dependencies - Avoid circular importsname-meaningful - Use intention-revealing namesname-consistent - Consistent naming conventionsname-searchable - Avoid magic numbers/stringsname-avoid-encodings - No Hungarian notationname-domain-language - Use domain terminologyfunc-small - Keep functions smallfunc-single-purpose - Do one thingfunc-few-arguments - Limit parametersfunc-no-side-effects - Minimize side effectsfunc-command-query - Separate commands and queriesdoc-self-documenting - Code should explain itselfdoc-why-not-what - Explain why, not whatdoc-avoid-noise - No redundant commentsdoc-api-docs - Document public APIsFor detailed examples and explanations, see the rule files:
| Principle | Definition |
|---|---|
| S ingle Responsibility | A class should have only one reason to change |
| O pen/Closed | Open for extension, closed for modification |
| L iskov Substitution | Subtypes must be substitutable for base types |
| I nterface Segregation | Don't force clients to depend on unused interfaces |
| D ependency Inversion | Depend on abstractions, not concretions |
| Principle | Definition |
|---|---|
| DRY | Don't Repeat Yourself - single source of truth |
| KISS | Keep It Simple - avoid over-engineering |
| YAGNI | You Aren't Gonna Need It - build only what's needed |
// Single Responsibility - one class, one job
class UserService {
constructor(
private validator: UserValidator,
private repository: UserRepository,
) {}
createUser(data) {
this.validator.validate(data);
return this.repository.create(data);
}
}
// Dependency Inversion - depend on abstractions
interface Repository<T> {
find(id: string): Promise<T | null>;
save(entity: T): Promise<T>;
}
class OrderService {
constructor(private repository: Repository<Order>) {}
}
// DRY - single source of truth
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const isValidEmail = (email: string) => EMAIL_REGEX.test(email);
// Meaningful names over magic numbers
const MINIMUM_AGE = 18;
if (user.age >= MINIMUM_AGE) { }
When auditing code, output findings in this format:
file:line - [principle] Description of issue
Example:
src/services/UserService.ts:15 - [solid-srp] Class handles validation, persistence, and notifications
src/utils/helpers.ts:42 - [core-dry] Email validation duplicated from validators/email.ts
src/models/Order.ts:28 - [name-meaningful] Variable 'x' should describe its purpose
Read individual rule files for detailed explanations:
rules/solid-srp-class.md
rules/core-dry.md
rules/pattern-repository.md
This skill is built on established software engineering principles:
Version: 1.0.2 Status: Active Coverage: 23 rules across 3 implemented categories (SOLID, Core Principles, Design Patterns); 4 planned Last Updated: 2026-03-07
Weekly Installs
339
Repository
GitHub Stars
18
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex285
opencode280
gemini-cli278
github-copilot260
cursor229
claude-code221
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
105,000 周安装
Cloudflare Images 图像托管与转换 API 使用指南 | 支持 AI 人脸裁剪与内容凭证
328 周安装
Swift iOS HomeKit Matter 开发指南:控制智能家居与设备配网
329 周安装
iOS WeatherKit 使用指南:获取天气数据、预报与警报的 Swift 实现
329 周安装
Microsoft Agent Framework 开发指南:统一Semantic Kernel与AutoGen的AI智能体框架
329 周安装
Spring缓存单元测试指南:@Cacheable、@CacheEvict、@CachePut测试方法与内存缓存管理器
329 周安装
React Native 升级指南:使用 upgrade-react-native 技能轻松升级项目版本
329 周安装