sc-principles
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese/sc:principles - Code Principles Validator
/sc:principles - 代码原则验证器
Mandatory validation skill enforcing four fundamental software engineering principles:
- KISS (Keep It Simple, Stupid) - Code should be as simple as possible
- Functional Core, Imperative Shell - Business logic must be pure; I/O belongs at edges
- SOLID - Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, Dependency Inversion
- Let It Crash - Fail fast for bugs; handle errors explicitly at boundaries
强制验证技能,实施四项核心软件工程原则:
- KISS (Keep It Simple, Stupid) - 代码应尽可能简洁
- 函数核心,命令式外壳 - 业务逻辑必须是纯函数;I/O操作应放在代码边缘
- SOLID - 单一职责、开闭原则、里氏替换、接口隔离、依赖反转
- Let It Crash - 针对bug快速失败;在边界处显式处理错误
Quick Start
快速开始
bash
undefinedbash
undefinedFull validation (all four principles)
完整验证(涵盖四项原则)
/sc:principles src/
/sc:principles src/
KISS only validation
仅执行KISS验证
/sc:principles src/ --kiss-only
/sc:principles src/ --kiss-only
Purity only validation
仅执行纯函数验证
/sc:principles src/ --purity-only
/sc:principles src/ --purity-only
SOLID only validation
仅执行SOLID验证
/sc:principles src/ --solid-only
/sc:principles src/ --solid-only
Let It Crash only validation
仅执行Let It Crash验证
/sc:principles src/ --crash-only
/sc:principles src/ --crash-only
Strict mode (warnings become errors)
严格模式(警告视为错误)
/sc:principles src/ --strict
/sc:principles src/ --strict
Generate detailed report
生成详细报告
/sc:principles src/ --report
undefined/sc:principles src/ --report
undefinedBehavioral Flow
行为流程
1. INITIALIZE
├── Detect scope root
├── Find changed Python files (git diff)
└── Determine file contexts (core vs shell)
2. ANALYZE
├── Parse AST for each file
├── Calculate complexity metrics (KISS)
├── Detect I/O patterns (Purity)
├── Check structural patterns (SOLID)
└── Analyze error handling (Let It Crash)
3. VALIDATE
├── Compare against thresholds
├── Classify violations (error vs warning)
└── Apply context rules (core stricter than shell)
4. REPORT/BLOCK
├── Output violations with locations
├── Generate actionable recommendations
└── Exit 0 (pass) or 2 (blocked)1. 初始化
├── 检测作用域根目录
├── 查找变更的Python文件(git diff)
└── 确定文件上下文(核心层 vs 外壳层)
2. 分析
├── 解析每个文件的AST
├── 计算复杂度指标(KISS)
├── 检测I/O模式(纯函数验证)
├── 检查结构模式(SOLID)
└── 分析错误处理(Let It Crash)
3. 验证
├── 与阈值进行对比
├── 分类违规类型(错误 vs 警告)
└── 应用上下文规则(核心层比外壳层更严格)
4. 报告/拦截
├── 输出带位置信息的违规内容
├── 生成可执行的建议
└── 返回0(通过)或2(拦截)的退出码Validation Rules
验证规则
KISS Gate
KISS验证关卡
| Metric | Threshold | Severity | Description |
|---|---|---|---|
| Cyclomatic Complexity | > 10 | error | Number of independent paths through code |
| Cyclomatic Complexity | > 7 | warning | Early warning for growing complexity |
| Cognitive Complexity | > 15 | error | Weighted complexity (nested structures count more) |
| Function Length | > 50 lines | error | Lines of code per function (inclusive count) |
| Nesting Depth | > 4 levels | error | If/for/while/with/try nesting |
| Parameter Count | > 5 | warning | Function parameters |
Cognitive vs Cyclomatic Complexity:
- Cyclomatic counts decision points (branches)
- Cognitive weights nested structures more heavily: per control structure
1 + nesting_depth - Example: has low cyclomatic but high cognitive (hard to read)
if (if (if ...))
| 指标 | 阈值 | 严重程度 | 描述 |
|---|---|---|---|
| 圈复杂度 | > 10 | 错误 | 代码中独立路径的数量 |
| 圈复杂度 | > 7 | 警告 | 复杂度上升的早期预警 |
| 认知复杂度 | > 15 | 错误 | 加权复杂度(嵌套结构权重更高) |
| 函数长度 | > 50行 | 错误 | 每个函数的代码行数(包含所有计数) |
| 嵌套深度 | > 4层 | 错误 | If/for/while/with/try的嵌套层级 |
| 参数数量 | > 5 | 警告 | 函数参数个数 |
认知复杂度 vs 圈复杂度:
- 圈复杂度统计决策点(分支)的数量
- 认知复杂度对嵌套结构赋予更高权重:每个控制结构按计算
1 + 嵌套深度 - 示例:的圈复杂度低,但认知复杂度高(难以阅读)
if (if (if ...))
Purity Gate
纯函数验证关卡
The "Functional Core, Imperative Shell" pattern:
| Layer | Path Patterns | I/O Allowed | Severity |
|---|---|---|---|
| Core | | NO | error |
| Shell | | YES | warning |
Note: Files in , , , , , and are treated as shell (I/O allowed).
*/archive/**/examples/**/benchmarks/*conftest.pysetup.py*__main__.pyDetected I/O Patterns:
| Category | Examples |
|---|---|
| File I/O | |
| Network | |
| Database | |
| Subprocess | |
| Global State | |
| Side Effects | |
| Async I/O | |
遵循「函数核心,命令式外壳」模式:
| 层级 | 路径模式 | 是否允许I/O | 严重程度 |
|---|---|---|---|
| 核心层 | | 不允许 | 错误 |
| 外壳层 | | 允许 | 警告 |
注意: , , , , 以及目录下的文件被视为外壳层(允许I/O操作)。
*/archive/**/examples/**/benchmarks/*conftest.pysetup.py*__main__.py检测到的I/O模式:
| 类别 | 示例 |
|---|---|
| 文件I/O | |
| 网络 | |
| 数据库 | |
| 子进程 | |
| 全局状态 | |
| 副作用 | |
| 异步I/O | |
SOLID Gate
SOLID验证关卡
Detects structural violations of SOLID design principles.
| Principle | Detection | Severity | Description |
|---|---|---|---|
| SRP | File >300 lines, class with >5 public methods | warning | Single Responsibility - one reason to change |
| OCP | | warning | Open-Closed - extend, don't modify |
| LSP | Override that raises | error | Liskov Substitution - honor contracts |
| ISP | Interface/protocol with >7 methods | warning | Interface Segregation - small interfaces |
| DIP | Direct instantiation in business logic | warning | Dependency Inversion - depend on abstractions |
Code Smells to Flag:
| Smell | Principle | Recommended Fix |
|---|---|---|
| File >300 lines | SRP | Extract responsibilities into modules |
| if/else type chains | OCP | Strategy pattern or registry |
| Override that throws | LSP | Honor base contract or don't inherit |
| 10+ method interface | ISP | Split into focused interfaces |
| DIP | Dependency injection |
检测SOLID设计原则的结构违规。
| 原则 | 检测方式 | 严重程度 | 描述 |
|---|---|---|---|
| SRP(单一职责) | 文件超过300行,类包含5个以上公共方法 | 警告 | 单一职责 - 只有一个修改理由 |
| OCP(开闭原则) | 基于类型的 | 警告 | 开闭原则 - 对扩展开放,对修改关闭 |
| LSP(里氏替换) | 重写方法抛出 | 错误 | 里氏替换 - 遵守基类契约 |
| ISP(接口隔离) | 接口/协议包含7个以上方法 | 警告 | 接口隔离 - 使用小而专的接口 |
| DIP(依赖反转) | 业务逻辑中直接实例化对象 | 警告 | 依赖反转 - 依赖抽象而非具体实现 |
需要标记的代码异味:
| 异味 | 涉及原则 | 推荐修复方案 |
|---|---|---|
| 文件超过300行 | SRP | 将职责拆分到多个模块中 |
| 基于类型的if/else链 | OCP | 使用策略模式或注册机制 |
| 重写方法抛出异常 | LSP | 遵守基类契约或不继承 |
| 包含10+方法的接口 | ISP | 将大接口拆分为多个专注的接口 |
逻辑中直接 | DIP | 使用依赖注入 |
Let It Crash Gate
Let It Crash验证关卡
Detects anti-patterns in error handling based on the "Let It Crash" philosophy.
| Pattern | Severity | Description |
|---|---|---|
Bare | error | Catches all exceptions including KeyboardInterrupt |
| warning | Swallows errors without handling |
| error | Silent failure, debugging nightmare |
Defensive | warning | Masks root cause of bugs |
| Nested try/except fallbacks | warning | Complex error paths, hard to debug |
When to Let It Crash:
- Validation failures → crash with clear error
- Programming errors → surface immediately
- Internal operations → let them fail
When to Handle Errors (exceptions to rule):
- Data persistence → protect against data loss
- External APIs → retry, fallback, graceful degradation
- Resource cleanup → RAII, finally blocks
- User-facing operations → graceful error messages
Not Flagged (appropriate handling):
- Error handling in ,
*/adapters/*,*/api/*paths*/cli/* - Explicit logging before swallowing
- Re-raise after logging
基于「Let It Crash」理念检测错误处理的反模式。
| 模式 | 严重程度 | 描述 |
|---|---|---|
裸 | 错误 | 捕获所有异常,包括KeyboardInterrupt |
| 警告 | 吞掉错误而不处理 |
| 错误 | 静默失败,调试噩梦 |
防御性的 | 警告 | 掩盖bug的根本原因 |
| 嵌套的try/except回退 | 警告 | 复杂的错误路径,难以调试 |
何时应Let It Crash:
- 验证失败 → 抛出清晰的错误并终止
- 编程错误 → 立即暴露问题
- 内部操作 → 让其失败
何时应处理错误(规则例外):
- 数据持久化 → 防止数据丢失
- 外部API → 重试、回退、优雅降级
- 资源清理 → RAII、finally块
- 面向用户的操作 → 优雅的错误提示
不会标记的情况(合理处理方式):
- ,
*/adapters/*,*/api/*路径中的错误处理*/cli/* - 吞掉错误前显式记录日志
- 记录日志后重新抛出异常
Flags
标志位
| Flag | Type | Default | Description |
|---|---|---|---|
| bool | false | Run only KISS validation |
| bool | false | Run only purity validation |
| bool | false | Run only SOLID validation |
| bool | false | Run only Let It Crash validation |
| bool | false | Skip KISS validation |
| bool | false | Skip purity validation |
| bool | false | Skip SOLID validation |
| bool | false | Skip Let It Crash validation |
| int | 10 | Max cyclomatic complexity |
| int | 15 | Max cognitive complexity |
| int | 50 | Max function line count |
| int | 4 | Max nesting depth |
| int | 5 | Max parameter count |
| int | 300 | Max file line count (SRP) |
| int | 7 | Max interface methods (ISP) |
| bool | false | Treat all warnings as errors |
| bool | false | Only validate core layer files |
| bool | false | Analyze all files, not just changed |
| bool | false | Generate detailed JSON report |
| 标志位 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| bool | false | 仅运行KISS验证 |
| bool | false | 仅运行纯函数验证 |
| bool | false | 仅运行SOLID验证 |
| bool | false | 仅运行Let It Crash验证 |
| bool | false | 跳过KISS验证 |
| bool | false | 跳过纯函数验证 |
| bool | false | 跳过SOLID验证 |
| bool | false | 跳过Let It Crash验证 |
| int | 10 | 最大圈复杂度 |
| int | 15 | 最大认知复杂度 |
| int | 50 | 函数最大行数 |
| int | 4 | 最大嵌套深度 |
| int | 5 | 最大参数数量 |
| int | 300 | 文件最大行数(SRP) |
| int | 7 | 接口最大方法数(ISP) |
| bool | false | 将所有警告视为错误 |
| bool | false | 仅验证核心层文件 |
| bool | false | 分析所有文件,而非仅变更的文件 |
| bool | false | 生成详细的JSON报告 |
Integration Flags
集成标志位
For use by other skills and pre-commit hooks:
| Flag | Description |
|---|---|
| Run as pre-commit hook (blocks commit on failure) |
| Real-time validation during implementation |
| Output JSON format for programmatic use |
供其他技能和提交前钩子使用:
| 标志位 | 描述 |
|---|---|
| 作为提交前钩子运行(失败时阻止提交) |
| 实现过程中的实时验证 |
| 输出JSON格式供程序调用 |
Exit Codes
退出码
| Code | Meaning | Action |
|---|---|---|
| 0 | Validation passed | Proceed |
| 2 | Violations detected | Blocked - refactor required |
| 3 | Validation error | Manual intervention needed |
| 代码 | 含义 | 操作 |
|---|---|---|
| 0 | 验证通过 | 继续执行 |
| 2 | 检测到违规 | 拦截 - 需要重构 |
| 3 | 验证错误 | 需要人工干预 |
Personas Activated
激活的角色
- code-warden - Primary reviewer for principles enforcement
- refactoring-expert - For complex refactoring guidance
- quality-engineer - For metrics integration
- code-warden - 原则执行的主要审核者
- refactoring-expert - 提供复杂重构指导
- quality-engineer - 负责指标集成
Validator Scripts
验证器脚本
Located in directory:
scripts/位于目录下:
scripts/validate_kiss.py
validate_kiss.py
bash
python .claude/skills/sc-principles/scripts/validate_kiss.py \
--scope-root . \
--threshold 10 \
--max-lines 50 \
--jsonbash
python .claude/skills/sc-principles/scripts/validate_kiss.py \
--scope-root . \
--threshold 10 \
--max-lines 50 \
--jsonvalidate_purity.py
validate_purity.py
bash
python .claude/skills/sc-principles/scripts/validate_purity.py \
--scope-root . \
--core-only \
--jsonbash
python .claude/skills/sc-principles/scripts/validate_purity.py \
--scope-root . \
--core-only \
--jsonPre-commit Integration
提交前钩子集成
Add to :
.pre-commit-config.yamlyaml
repos:
- repo: local
hooks:
- id: kiss-check
name: KISS Validation
entry: python .claude/skills/sc-principles/scripts/validate_kiss.py --scope-root . --json
language: python
types: [python]
pass_filenames: false
- id: purity-check
name: Purity Validation
entry: python .claude/skills/sc-principles/scripts/validate_purity.py --scope-root . --json
language: python
types: [python]
pass_filenames: false添加到:
.pre-commit-config.yamlyaml
repos:
- repo: local
hooks:
- id: kiss-check
name: KISS Validation
entry: python .claude/skills/sc-principles/scripts/validate_kiss.py --scope-root . --json
language: python
types: [python]
pass_filenames: false
- id: purity-check
name: Purity Validation
entry: python .claude/skills/sc-principles/scripts/validate_purity.py --scope-root . --json
language: python
types: [python]
pass_filenames: falseRefactoring Guidance
重构指导
When violations are detected, apply these patterns:
检测到违规时,应用以下模式:
For Complexity Violations
针对复杂度违规
- Extract Method - Split large functions into smaller, named pieces
- Guard Clauses - Replace nested if/else with early returns
- Strategy Pattern - Replace complex switch/if-else with polymorphism
- Decompose Conditional - Name complex conditions as explaining variables
Before:
python
def process(data, config, user):
if data:
if config.enabled:
if user.has_permission:
for item in data:
if item.valid:
# deep logic hereAfter:
python
def process(data, config, user):
if not can_process(data, config, user):
return None
return process_items(data)
def can_process(data, config, user):
return data and config.enabled and user.has_permission
def process_items(data):
return [process_item(item) for item in data if item.valid]- 提取方法 - 将大函数拆分为更小、命名清晰的函数
- 卫语句 - 用提前返回替代嵌套if/else
- 策略模式 - 用多态替代复杂的switch/if-else
- 分解条件 - 将复杂条件命名为解释性变量
重构前:
python
def process(data, config, user):
if data:
if config.enabled:
if user.has_permission:
for item in data:
if item.valid:
# 深层逻辑重构后:
python
def process(data, config, user):
if not can_process(data, config, user):
return None
return process_items(data)
def can_process(data, config, user):
return data and config.enabled and user.has_permission
def process_items(data):
return [process_item(item) for item in data if item.valid]For Purity Violations
针对纯函数违规
- Dependency Injection - Pass dependencies as arguments
- Repository Pattern - Isolate database operations
- Adapter Pattern - Wrap external APIs
- Return Don't Print - Return values, let callers handle output
Before:
python
undefined- 依赖注入 - 将依赖作为参数传入
- 仓库模式 - 隔离数据库操作
- 适配器模式 - 封装外部API
- 返回而非打印 - 返回值,由调用者处理输出
重构前:
python
undefinedIn domain/calculator.py (CORE - should be pure)
在domain/calculator.py(核心层 - 应为纯函数)
def calculate_discount(user_id):
user = db.query(User).get(user_id) # I/O in core!
print(f"Calculating for {user.name}") # Side effect!
return 0.2 if user.is_premium else 0.1
**After:**
```pythondef calculate_discount(user_id):
user = db.query(User).get(user_id) # 核心层存在I/O操作!
print(f"Calculating for {user.name}") # 存在副作用!
return 0.2 if user.is_premium else 0.1
**重构后:**
```pythonIn domain/calculator.py (CORE - now pure)
在domain/calculator.py(核心层 - 现在是纯函数)
def calculate_discount(user: User) -> float:
"""Pure function - no I/O, just logic."""
return 0.2 if user.is_premium else 0.1
def calculate_discount(user: User) -> float:
"""纯函数 - 无I/O,仅包含逻辑。"""
return 0.2 if user.is_premium else 0.1
In adapters/discount_service.py (SHELL - I/O allowed)
在adapters/discount_service.py(外壳层 - 允许I/O)
def get_user_discount(user_id: int) -> float:
user = user_repository.get(user_id)
discount = calculate_discount(user)
logger.info(f"Discount for {user.name}: {discount}")
return discount
undefineddef get_user_discount(user_id: int) -> float:
user = user_repository.get(user_id)
discount = calculate_discount(user)
logger.info(f"Discount for {user.name}: {discount}")
return discount
undefinedFor SOLID Violations
针对SOLID违规
- SRP (Single Responsibility) - Extract into modules
- OCP (Open-Closed) - Use strategy pattern or registry
- LSP (Liskov Substitution) - Honor base contracts
- ISP (Interface Segregation) - Split fat interfaces
- DIP (Dependency Inversion) - Inject dependencies
Before (OCP violation):
python
def process_payment(payment_type, amount):
if payment_type == "credit":
return process_credit(amount)
elif payment_type == "debit":
return process_debit(amount)
elif payment_type == "crypto": # New type = code change!
return process_crypto(amount)After (OCP compliant):
python
PROCESSORS = {
"credit": process_credit,
"debit": process_debit,
"crypto": process_crypto, # Add here, no function change
}
def process_payment(payment_type, amount):
processor = PROCESSORS.get(payment_type)
if not processor:
raise ValueError(f"Unknown payment type: {payment_type}")
return processor(amount)- SRP(单一职责) - 将职责拆分到多个模块
- OCP(开闭原则) - 使用策略模式或注册机制
- LSP(里氏替换) - 遵守基类契约
- ISP(接口隔离) - 拆分大接口
- DIP(依赖反转) - 注入依赖
重构前(违反OCP):
python
def process_payment(payment_type, amount):
if payment_type == "credit":
return process_credit(amount)
elif payment_type == "debit":
return process_debit(amount)
elif payment_type == "crypto": # 新增类型需要修改代码!
return process_crypto(amount)重构后(符合OCP):
python
PROCESSORS = {
"credit": process_credit,
"debit": process_debit,
"crypto": process_crypto, # 在此添加,无需修改函数
}
def process_payment(payment_type, amount):
processor = PROCESSORS.get(payment_type)
if not processor:
raise ValueError(f"Unknown payment type: {payment_type}")
return processor(amount)For Let It Crash Violations
针对Let It Crash违规
- Remove catch-all blocks - Let bugs surface
- Remove defensive guards - Validate at boundaries instead
- Flatten try/except - Handle at edges, not everywhere
Before (catch-all anti-pattern):
python
def get_user(user_id):
try:
user = db.query(User).get(user_id)
return user
except: # BAD: catches everything, hides bugs
return NoneAfter (let it crash):
python
def get_user(user_id):
# Let database errors surface - they indicate real problems
return db.query(User).get(user_id)- 移除全局捕获块 - 让bug暴露出来
- 移除防御性检查 - 改为在边界处验证
- 扁平化try/except - 在边缘处理,而非到处处理
重构前(全局捕获反模式):
python
def get_user(user_id):
try:
user = db.query(User).get(user_id)
return user
except: # 错误:捕获所有异常,隐藏bug
return None重构后(Let It Crash):
python
def get_user(user_id):
# 让数据库错误暴露出来 - 它们代表真实的问题
return db.query(User).get(user_id)Handle at the boundary (API layer)
在边界处处理(API层)
@app.get("/users/{user_id}")
def api_get_user(user_id: int):
try:
return get_user(user_id)
except DBError as e:
logger.error("Database error", error=e, user_id=user_id)
raise HTTPException(500, "Database unavailable")
undefined@app.get("/users/{user_id}")
def api_get_user(user_id: int):
try:
return get_user(user_id)
except DBError as e:
logger.error("Database error", error=e, user_id=user_id)
raise HTTPException(500, "Database unavailable")
undefinedExamples
示例
Example 1: Full Validation
示例1:完整验证
bash
$ /sc:principles src/ --report
KISS Validation: BLOCKED
Files analyzed: 12
Errors: 3, Warnings: 5
Violations:
[ERROR] src/services/order.py:45 process_order: complexity = 15 (max: 10)
[ERROR] src/utils/parser.py:12 parse_data: length = 78 (max: 50)
[WARNING] src/domain/calc.py:8 calculate: parameters = 7 (max: 5)
Purity Validation: BLOCKED
Core violations: 2, Shell warnings: 1
Violations:
[ERROR] src/domain/user.py:23 get_status: database - db.query (context: core)
[ERROR] src/services/report.py:56 generate: file_io - open (context: core)
Recommendations:
- COMPLEXITY: Extract helper functions, use early returns
- DATABASE: Use repository pattern. Business logic receives data, not queries
- FILE I/O: Move file operations to adapter layerbash
$ /sc:principles src/ --report
KISS验证:拦截
分析文件数:12
错误数:3,警告数:5
违规内容:
[错误] src/services/order.py:45 process_order: 复杂度 = 15(最大值:10)
[错误] src/utils/parser.py:12 parse_data: 长度 = 78(最大值:50)
[警告] src/domain/calc.py:8 calculate: 参数 = 7(最大值:5)
纯函数验证:拦截
核心层违规数:2,外壳层警告数:1
违规内容:
[错误] src/domain/user.py:23 get_status: 数据库 - db.query(上下文:核心层)
[错误] src/services/report.py:56 generate: 文件I/O - open(上下文:核心层)
建议:
- 复杂度:提取辅助函数,使用提前返回
- 数据库:使用仓库模式。业务逻辑接收数据,而非直接查询
- 文件I/O:将文件操作移至适配器层Example 2: KISS Only
示例2:仅KISS验证
bash
$ /sc:principles src/ --kiss-only --threshold 8
KISS Validation: PASSED
Files analyzed: 12
Errors: 0, Warnings: 2bash
$ /sc:principles src/ --kiss-only --threshold 8
KISS验证:通过
分析文件数:12
错误数:0,警告数:2Example 3: Strict Mode
示例3:严格模式
bash
$ /sc:principles src/ --strictbash
$ /sc:principles src/ --strictAll warnings become errors
所有警告均视为错误
Any warning will block
任何警告都会拦截提交
undefinedundefinedQuality Integration
质量集成
This skill integrates with SuperClaude quality gates:
- Contributes to dimension (weight: 0.08)
simplicity - Contributes to dimension (weight: 0.02)
purity - Triggers strategy when simplicity < 70
simplification - Triggers strategy when purity < 70
purification
本技能与SuperClaude质量关卡集成:
- 贡献于维度(权重:0.08)
简洁性 - 贡献于维度(权重:0.02)
纯函数 - 当简洁性 < 70时触发策略
简化 - 当纯函数得分 < 70时触发策略
纯净化
Related Skills
相关技能
- - Auto-refactor for principles compliance
/sc:improve --type principles - - Includes principles validation by default
/sc:implement - - Code analysis includes principles metrics
/sc:analyze
- - 自动重构以符合原则要求
/sc:improve --type principles - - 默认包含原则验证
/sc:implement - - 代码分析包含原则指标
/sc:analyze
Test Coverage
测试覆盖率
The validators have comprehensive test coverage (27 tests):
Purity Validator Tests:
- Async function detection ()
async def - Await expression detection
- Async for loop detection
- Async with context manager detection
- Shell vs core severity differentiation
- Edge cases (syntax errors, unicode, empty files)
KISS Validator Tests:
- Function length (inclusive count)
- Cyclomatic complexity
- Cognitive complexity
- Nesting depth
- Parameter count
- Edge cases (syntax errors, unicode, empty files)
Run tests:
bash
python -m pytest .claude/skills/sc-principles/tests/ -vVersion: 2.0.0
Validators: , , (heuristic), (heuristic)
Agent:
Traits: ,
Tests: 27 passing (KISS + Purity)
validate_kiss.pyvalidate_purity.pyvalidate_solid.pyvalidate_crash.pycode-wardensolid-alignedcrash-resilient验证器具有全面的测试覆盖率(27个测试用例):
纯函数验证器测试:
- 异步函数检测()
async def - Await表达式检测
- 异步for循环检测
- 异步with上下文管理器检测
- 外壳层与核心层的严重程度区分
- 边缘情况(语法错误、Unicode、空文件)
KISS验证器测试:
- 函数长度(包含性计数)
- 圈复杂度
- 认知复杂度
- 嵌套深度
- 参数数量
- 边缘情况(语法错误、Unicode、空文件)
运行测试:
bash
python -m pytest .claude/skills/sc-principles/tests/ -v版本: 2.0.0
验证器: , , (启发式), (启发式)
Agent:
特性: ,
测试: 27个通过(KISS + 纯函数)
validate_kiss.pyvalidate_purity.pyvalidate_solid.pyvalidate_crash.pycode-wardensolid-alignedcrash-resilient