opencode-skills-collection 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundled-skills/.antigravity-install-manifest.json +24 -1
- package/bundled-skills/007/SKILL.md +2 -2
- package/bundled-skills/10-andruia-skill-smith/SKILL.md +1 -1
- package/bundled-skills/agent-squad/SKILL.md +5 -0
- package/bundled-skills/agent-squad/alex/SKILL.md +3 -0
- package/bundled-skills/agent-squad/aria/SKILL.md +3 -0
- package/bundled-skills/agent-squad/dep/SKILL.md +3 -0
- package/bundled-skills/agent-squad/luna/SKILL.md +4 -1
- package/bundled-skills/agent-squad/mason/SKILL.md +3 -0
- package/bundled-skills/agent-squad/max/SKILL.md +3 -0
- package/bundled-skills/agent-squad/quinn/SKILL.md +3 -0
- package/bundled-skills/agent-squad/rex/SKILL.md +3 -0
- package/bundled-skills/angular/metadata.json +1 -1
- package/bundled-skills/angular-best-practices/metadata.json +1 -1
- package/bundled-skills/angular-state-management/metadata.json +1 -1
- package/bundled-skills/angular-ui-patterns/metadata.json +1 -1
- package/bundled-skills/antigravity-skill-orchestrator/SKILL.md +2 -2
- package/bundled-skills/apify-actor-development/SKILL.md +2 -2
- package/bundled-skills/apple-container/SKILL.md +165 -0
- package/bundled-skills/apple-container/references/commands.md +1593 -0
- package/bundled-skills/apple-container/references/concepts.md +294 -0
- package/bundled-skills/apple-container/references/configuration.md +499 -0
- package/bundled-skills/apple-container/references/workflows.md +498 -0
- package/bundled-skills/ask-copilot/SKILL.md +112 -0
- package/bundled-skills/auto-research/SKILL.md +126 -0
- package/bundled-skills/brooks-lint/SKILL.md +1 -1
- package/bundled-skills/browser-harness/references/install.md +3 -1
- package/bundled-skills/chrome-extension-developer/SKILL.md +1 -1
- package/bundled-skills/clean-code-guard/SKILL.md +184 -0
- package/bundled-skills/clean-code-guard/references/ai-failure-modes.md +345 -0
- package/bundled-skills/clean-code-guard/references/comments-and-formatting.md +115 -0
- package/bundled-skills/clean-code-guard/references/dry-kiss-yagni.md +133 -0
- package/bundled-skills/clean-code-guard/references/naming-and-functions.md +187 -0
- package/bundled-skills/clean-code-guard/references/review-checklist.md +150 -0
- package/bundled-skills/clean-code-guard/references/solid.md +280 -0
- package/bundled-skills/clean-code-guard/references/sources.md +47 -0
- package/bundled-skills/cloudflare-security-audit/SKILL.md +137 -0
- package/bundled-skills/cloudflare-security-audit/references/AI-AND-LLM.md +67 -0
- package/bundled-skills/cloudflare-security-audit/references/ATTACK-CLASSES.md +116 -0
- package/bundled-skills/cloudflare-security-audit/references/CLIENT-SIDE.md +67 -0
- package/bundled-skills/cloudflare-security-audit/references/HUNTING.md +110 -0
- package/bundled-skills/cloudflare-security-audit/references/MEMORY-SAFETY-AND-BINARY.md +58 -0
- package/bundled-skills/cloudflare-security-audit/references/RECONNAISSANCE.md +46 -0
- package/bundled-skills/cloudflare-security-audit/references/VALIDATION-AND-REPORTING.md +109 -0
- package/bundled-skills/cloudflare-security-audit/references/WEB-PROTOCOL-AND-AUTH.md +85 -0
- package/bundled-skills/cloudflare-security-audit/resources/report-schema.json +210 -0
- package/bundled-skills/comfyui-gateway/references/troubleshooting.md +1 -1
- package/bundled-skills/commit/SKILL.md +2 -1
- package/bundled-skills/deepapi/SKILL.md +6 -6
- package/bundled-skills/docs/README.md +1 -1
- package/bundled-skills/docs/contributors/quality-bar.md +1 -1
- package/bundled-skills/docs/contributors/security-guardrails.md +1 -1
- package/bundled-skills/docs/integrations/jetski-cortex.md +5 -5
- package/bundled-skills/docs/integrations/jetski-gemini-loader/README.md +3 -3
- package/bundled-skills/docs/maintainers/ci-drift-fix.md +7 -5
- package/bundled-skills/docs/maintainers/merge-batch.md +24 -7
- package/bundled-skills/docs/maintainers/pr-autonomy.md +89 -0
- package/bundled-skills/docs/maintainers/release-notes-7.2.0.md +1 -1
- package/bundled-skills/docs/maintainers/release-process.md +9 -9
- package/bundled-skills/docs/maintainers/repo-growth-seo.md +5 -5
- package/bundled-skills/docs/maintainers/skills-date-tracking.md +1 -1
- package/bundled-skills/docs/maintainers/skills-update-guide.md +2 -2
- package/bundled-skills/docs/users/{antigravity-awesome-skills-vs-awesome-claude-skills.md → agentic-awesome-skills-vs-awesome-claude-skills.md} +5 -5
- package/bundled-skills/docs/users/ai-agent-skills.md +4 -4
- package/bundled-skills/docs/users/best-claude-code-skills-github.md +3 -3
- package/bundled-skills/docs/users/best-cursor-skills-github.md +3 -3
- package/bundled-skills/docs/users/bundles.md +56 -57
- package/bundled-skills/docs/users/claude-code-skills.md +6 -6
- package/bundled-skills/docs/users/codex-cli-skills.md +5 -5
- package/bundled-skills/docs/users/cursor-skills.md +3 -3
- package/bundled-skills/docs/users/faq.md +27 -15
- package/bundled-skills/docs/users/gemini-cli-skills.md +4 -4
- package/bundled-skills/docs/users/getting-started.md +22 -12
- package/bundled-skills/docs/users/kiro-integration.md +7 -7
- package/bundled-skills/docs/users/plugins.md +8 -9
- package/bundled-skills/docs/users/security-skills.md +1 -1
- package/bundled-skills/docs/users/skills-vs-mcp-tools.md +1 -1
- package/bundled-skills/docs/users/specialized-plugin-roadmap.md +3 -4
- package/bundled-skills/docs/users/usage.md +9 -9
- package/bundled-skills/docs/users/visual-guide.md +7 -7
- package/bundled-skills/docs/users/windows-truncation-recovery.md +1 -1
- package/bundled-skills/docs/users/workflows.md +1 -1
- package/bundled-skills/docs/vietnamese/BUNDLES.vi.md +1 -1
- package/bundled-skills/docs/vietnamese/FAQ.vi.md +15 -8
- package/bundled-skills/docs/vietnamese/GETTING_STARTED.vi.md +12 -5
- package/bundled-skills/docs/vietnamese/QUALITY_BAR.vi.md +1 -1
- package/bundled-skills/docs/vietnamese/README.vi.md +21 -17
- package/bundled-skills/docs/vietnamese/SECURITY_GUARDRAILS.vi.md +1 -1
- package/bundled-skills/docs/vietnamese/SKILLS_README.vi.md +2 -2
- package/bundled-skills/docs/vietnamese/TRANSLATION_PLAN.vi.md +1 -1
- package/bundled-skills/docs/vietnamese/VISUAL_GUIDE.vi.md +8 -8
- package/bundled-skills/docs-guard/SKILL.md +109 -0
- package/bundled-skills/docs-guard/references/code-samples.md +46 -0
- package/bundled-skills/docs-guard/references/docstrings.md +60 -0
- package/bundled-skills/docs-guard/references/review-checklist.md +45 -0
- package/bundled-skills/docs-guard/references/sources.md +22 -0
- package/bundled-skills/docs-guard/references/verification.md +51 -0
- package/bundled-skills/efficient-web-research/SKILL.md +4 -0
- package/bundled-skills/electron-development/SKILL.md +1 -1
- package/bundled-skills/event-staffing-compliance/SKILL.md +3 -0
- package/bundled-skills/event-staffing-ordering/SKILL.md +3 -0
- package/bundled-skills/feature-tracking/SKILL.md +222 -0
- package/bundled-skills/flutter-expert/SKILL.md +6 -1
- package/bundled-skills/flutter-expert/resources/implementation-playbook.md +214 -0
- package/bundled-skills/gemini-deep-research/README.md +246 -0
- package/bundled-skills/gemini-deep-research/SKILL.md +136 -0
- package/bundled-skills/gemini-deep-research/requirements.txt +2 -0
- package/bundled-skills/gemini-deep-research/scripts/research.py +692 -0
- package/bundled-skills/git-pushing/SKILL.md +21 -4
- package/bundled-skills/git-pushing/scripts/smart_commit.sh +206 -11
- package/bundled-skills/go-in-depth/scripts/workflow-script.js +4 -1
- package/bundled-skills/grok-build/SKILL.md +167 -0
- package/bundled-skills/grok-build/references/cli.md +99 -0
- package/bundled-skills/huggingface-tool-builder/references/find_models_by_paper.sh +1 -1
- package/bundled-skills/idea-autopsy/SKILL.md +147 -0
- package/bundled-skills/it-manager-hospital/README.md +1 -1
- package/bundled-skills/it-manager-pro/README.md +1 -1
- package/bundled-skills/itil-expert/README.md +1 -1
- package/bundled-skills/langgraph/SKILL.md +1 -1
- package/bundled-skills/linkedin-content-generator/SKILL.md +1 -1
- package/bundled-skills/lint-and-validate/scripts/lint_runner.py +23 -23
- package/bundled-skills/lint-and-validate/scripts/type_coverage.py +30 -30
- package/bundled-skills/logic-lens/SKILL.md +1 -1
- package/bundled-skills/lore/LICENSE +21 -0
- package/bundled-skills/lore/README.md +386 -0
- package/bundled-skills/lore/README.zh-CN.md +386 -0
- package/bundled-skills/lore/SKILL.md +453 -0
- package/bundled-skills/lore/WORKFLOWS.md +216 -0
- package/bundled-skills/lore/WORKFLOWS.zh-CN.md +216 -0
- package/bundled-skills/lore/references/audit-template.md +60 -0
- package/bundled-skills/lore/references/compatibility.md +228 -0
- package/bundled-skills/lore/references/config.md +125 -0
- package/bundled-skills/lore/references/entry-format.md +70 -0
- package/bundled-skills/lore/references/history-command.md +106 -0
- package/bundled-skills/lore/references/monorepo-detection.md +78 -0
- package/bundled-skills/lore/references/platform-mirrors.md +377 -0
- package/bundled-skills/lore/references/stale-new-markers.md +62 -0
- package/bundled-skills/lore/references/summary-template.md +98 -0
- package/bundled-skills/lore/scripts/README.md +54 -0
- package/bundled-skills/lore/scripts/README.zh-CN.md +54 -0
- package/bundled-skills/lore/scripts/find_duplicates.py +211 -0
- package/bundled-skills/lore/scripts/find_stale.py +116 -0
- package/bundled-skills/lore/scripts/history.py +527 -0
- package/bundled-skills/lore/scripts/id_hash.py +32 -0
- package/bundled-skills/lore/scripts/list_entries.py +183 -0
- package/bundled-skills/lovable-cleanup/SKILL.md +3 -3
- package/bundled-skills/makepad-splash/SKILL.md +1 -1
- package/bundled-skills/mmx-cli/SKILL.md +14 -1
- package/bundled-skills/monopoly/SKILL.md +5 -0
- package/bundled-skills/monopoly/patterns/SKILL.md +4 -0
- package/bundled-skills/monopoly/scale-benchmarks/SKILL.md +4 -0
- package/bundled-skills/monopoly/security-checklist/SKILL.md +4 -0
- package/bundled-skills/monopoly/tech-matrix/SKILL.md +4 -0
- package/bundled-skills/mtls-configuration/SKILL.md +1 -1
- package/bundled-skills/network-101/SKILL.md +4 -5
- package/bundled-skills/nika/SKILL.md +270 -0
- package/bundled-skills/not-a-vibe-coder/SKILL.md +4 -0
- package/bundled-skills/ontoly-software-graph/SKILL.md +160 -0
- package/bundled-skills/openclaw-github-repo-commander/SKILL.md +1 -1
- package/bundled-skills/pilot-protocol/SKILL.md +6 -3
- package/bundled-skills/postgres-readonly-queries/README.md +77 -0
- package/bundled-skills/postgres-readonly-queries/SKILL.md +152 -0
- package/bundled-skills/postgres-readonly-queries/connections.example.json +34 -0
- package/bundled-skills/postgres-readonly-queries/requirements.txt +1 -0
- package/bundled-skills/postgres-readonly-queries/scripts/query.py +262 -0
- package/bundled-skills/pptx-deck-creation/SKILL.md +275 -0
- package/bundled-skills/pptx-deck-creation/references/audit-checklist.md +156 -0
- package/bundled-skills/pptx-deck-creation/references/design-profiles.md +96 -0
- package/bundled-skills/pptx-deck-creation/references/python-snippets.md +150 -0
- package/bundled-skills/pptx-deck-creation/references/reference-deck-analysis.md +91 -0
- package/bundled-skills/pptx-deck-creation/references/visual-asset-adapters.md +158 -0
- package/bundled-skills/privilege-escalation-methods/SKILL.md +1 -1
- package/bundled-skills/product-decision-agent/SKILL.md +94 -0
- package/bundled-skills/product-decision-agent/agents/openai.yaml +7 -0
- package/bundled-skills/product-decision-agent/references/methodology-basis.md +232 -0
- package/bundled-skills/product-decision-agent/references/product-playbooks.md +813 -0
- package/bundled-skills/product-decision-agent/references/reasoning-engine.md +289 -0
- package/bundled-skills/product-decision-agent/references/response-examples.md +279 -0
- package/bundled-skills/product-decision-agent/scripts/quality_gate.py +221 -0
- package/bundled-skills/product-decision-agent/scripts/test_quality_gate.py +94 -0
- package/bundled-skills/pytest-skill/reference/playbook.md +358 -0
- package/bundled-skills/quit-sponsor/SKILL.md +96 -0
- package/bundled-skills/rclone-cli/references/providers/s3.md +1 -1
- package/bundled-skills/security-and-hardening/SKILL.md +1 -1
- package/bundled-skills/semgrep-rule-creator/SKILL.md +6 -6
- package/bundled-skills/skill-creator/README.md +3 -3
- package/bundled-skills/skill-creator/SKILL.md +8 -4
- package/bundled-skills/skill-creator/scripts/quick_validate.py +1 -1
- package/bundled-skills/sql-injection-testing/SKILL.md +4 -4
- package/bundled-skills/subagent-orchestrator/README.md +1 -1
- package/bundled-skills/super-code/bash/SKILL.md +3 -0
- package/bundled-skills/super-code/c/SKILL.md +3 -0
- package/bundled-skills/super-code/cpp/SKILL.md +3 -0
- package/bundled-skills/super-code/csharp/SKILL.md +3 -0
- package/bundled-skills/super-code/dart/SKILL.md +3 -0
- package/bundled-skills/super-code/elixir/SKILL.md +3 -0
- package/bundled-skills/super-code/go/SKILL.md +3 -0
- package/bundled-skills/super-code/java/SKILL.md +3 -0
- package/bundled-skills/super-code/kotlin/SKILL.md +3 -0
- package/bundled-skills/super-code/php/SKILL.md +3 -0
- package/bundled-skills/super-code/python/SKILL.md +3 -0
- package/bundled-skills/super-code/ruby/SKILL.md +3 -0
- package/bundled-skills/super-code/rust/SKILL.md +3 -0
- package/bundled-skills/super-code/scala/SKILL.md +3 -0
- package/bundled-skills/super-code/swift/SKILL.md +3 -0
- package/bundled-skills/super-code/typescript/SKILL.md +3 -0
- package/bundled-skills/telegram-bot-messaging/README.md +185 -0
- package/bundled-skills/telegram-bot-messaging/SKILL.md +101 -0
- package/bundled-skills/telegram-bot-messaging/scripts/telegram.sh +420 -0
- package/bundled-skills/test-guard/SKILL.md +132 -0
- package/bundled-skills/test-guard/references/jest.md +50 -0
- package/bundled-skills/test-guard/references/llm-app-testing.md +40 -0
- package/bundled-skills/test-guard/references/phpunit.md +56 -0
- package/bundled-skills/test-guard/references/pytest.md +65 -0
- package/bundled-skills/trading-ledger/SKILL.md +11 -3
- package/bundled-skills/uizze-ui-research/SKILL.md +93 -0
- package/bundled-skills/vibe-code-auditor/SKILL.md +1 -1
- package/bundled-skills/vibecode-production-qa-validator/SKILL.md +1 -1
- package/bundled-skills/videodb/scripts/ws_listener.py +29 -15
- package/bundled-skills/voice-ai-engine-development/README.md +1 -1
- package/bundled-skills/vulnerability-scanner/SKILL.md +1 -1
- package/bundled-skills/warehouse/SKILL.md +154 -0
- package/bundled-skills/woo-guard/SKILL.md +113 -0
- package/bundled-skills/woo-guard/references/checkout-and-money.md +64 -0
- package/bundled-skills/woo-guard/references/hpos-and-crud.md +87 -0
- package/bundled-skills/woo-guard/references/review-checklist.md +44 -0
- package/bundled-skills/woo-guard/references/sources.md +17 -0
- package/bundled-skills/wp-guard/SKILL.md +119 -0
- package/bundled-skills/wp-guard/references/i18n.md +88 -0
- package/bundled-skills/wp-guard/references/performance.md +70 -0
- package/bundled-skills/wp-guard/references/review-checklist.md +57 -0
- package/bundled-skills/wp-guard/references/security.md +100 -0
- package/bundled-skills/wp-guard/references/sources.md +27 -0
- package/bundled-skills/writing-skills/gotchas.md +1 -1
- package/bundled-skills/writing-skills/references/standards/metadata-standard.md +1 -1
- package/bundled-skills/x-twitter-scraper/SKILL.md +14 -32
- package/bundled-skills/xss-html-injection/SKILL.md +3 -3
- package/bundled-skills/youtube-seo-optimizer/SKILL.md +1 -1
- package/bundled-skills/youtube-summarizer/CHANGELOG.md +2 -2
- package/package.json +1 -1
- package/skills_index.json +273 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# Naming and Functions — Clean Code Chapters 2 and 3
|
|
2
|
+
|
|
3
|
+
Source: Robert C. Martin, *Clean Code*. Sample chapters online at the Pearson PDF; chapter summaries at Vivek Khatri's Ch. 2 notes and Herberto Graça's Ch. 3 summary.
|
|
4
|
+
|
|
5
|
+
## Contents
|
|
6
|
+
|
|
7
|
+
- Meaningful names
|
|
8
|
+
- N1. Intention-revealing
|
|
9
|
+
- N2. No disinformation, no encodings
|
|
10
|
+
- N3. Meaningful distinctions
|
|
11
|
+
- N4. Searchable, pronounceable
|
|
12
|
+
- N5. Class names are nouns, method names are verbs
|
|
13
|
+
- N6. Banned generic names
|
|
14
|
+
- Functions
|
|
15
|
+
- F1. Small. Then smaller.
|
|
16
|
+
- F2. Do one thing
|
|
17
|
+
- F3. One level of abstraction per function
|
|
18
|
+
- F4. Step-down rule
|
|
19
|
+
- F5. Few arguments
|
|
20
|
+
- F6. No flag arguments
|
|
21
|
+
- F7. No output arguments / Command-Query Separation
|
|
22
|
+
- F8. No side effects in queries
|
|
23
|
+
- F9. Prefer exceptions to return codes
|
|
24
|
+
- F10. Duplication is the root evil
|
|
25
|
+
- Self-check for naming and functions
|
|
26
|
+
|
|
27
|
+
## Meaningful names
|
|
28
|
+
|
|
29
|
+
### N1. Intention-revealing
|
|
30
|
+
|
|
31
|
+
A name should tell you *why it exists, what it does, and how it's used*. If you need a comment to explain a name, the name is wrong.
|
|
32
|
+
|
|
33
|
+
**Bad:**
|
|
34
|
+
```text
|
|
35
|
+
d // elapsed time in days
|
|
36
|
+
ts = []
|
|
37
|
+
fn(xs)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Good:**
|
|
41
|
+
```text
|
|
42
|
+
elapsedDays
|
|
43
|
+
timestamps
|
|
44
|
+
filterOverdueInvoices(invoices)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### N2. No disinformation, no encodings
|
|
48
|
+
|
|
49
|
+
No Hungarian notation (`strName`, `iCount`). No interface-prefix `I` (`IUserService`). No member prefix `m_`. No "List" suffix unless the type is actually a list (`accountList` for a `set` is disinformation).
|
|
50
|
+
|
|
51
|
+
**Bad:** `strFirstName`, `IUserRepo`, `m_count`, `userArray` (when it is not an array).
|
|
52
|
+
|
|
53
|
+
**Good:** `first_name`, `UserRepo`, `count`, `users_by_id`.
|
|
54
|
+
|
|
55
|
+
### N3. Meaningful distinctions
|
|
56
|
+
|
|
57
|
+
Do not differentiate names by adding noise words. `ProductInfo`, `ProductData`, `Product` — what's the difference? Same with `getActiveAccount` vs. `getActiveAccountInfo`. If the distinction is real, name the distinction.
|
|
58
|
+
|
|
59
|
+
### N4. Searchable, pronounceable
|
|
60
|
+
|
|
61
|
+
Single-letter names are acceptable inside short loop scope (`for i in range(...)`). Anywhere else they hurt grep. `MAX_RETRIES` is searchable; `7` is not.
|
|
62
|
+
|
|
63
|
+
If you can't read the name aloud in a code review, it's a bad name. `genymdhms` is a real-world example from the book — `generation_timestamp` is the fix.
|
|
64
|
+
|
|
65
|
+
### N5. Class names are nouns, method names are verbs
|
|
66
|
+
|
|
67
|
+
`User`, `Invoice`, `Account` — classes are things. `saveInvoice`, `computeTotal`, `notifyUser` — methods are actions. A class named `ProcessInvoice` and a method named `Invoice` are both wrong.
|
|
68
|
+
|
|
69
|
+
### N6. Banned generic names
|
|
70
|
+
|
|
71
|
+
Without a qualifier, these names always violate intention-revealing:
|
|
72
|
+
|
|
73
|
+
- `data`, `data2`, `data_final`
|
|
74
|
+
- `result`, `result_final`
|
|
75
|
+
- `item`, `value`, `temp`, `obj`, `info`
|
|
76
|
+
- `helper`, `manager`, `utils`, `common`
|
|
77
|
+
- `handle_*`, `process_*`, `do_*` (when `*` is also generic)
|
|
78
|
+
|
|
79
|
+
Qualified versions are fine: `raw_csv_bytes`, `parsed_invoice`, `dedup_by_email`.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Functions
|
|
84
|
+
|
|
85
|
+
### F1. Small. Then smaller.
|
|
86
|
+
|
|
87
|
+
Target ≤20 lines. Uncle Bob's harder pass says 2–4 lines is the goal. If a function does not fit on a screen, it does too much. Extract.
|
|
88
|
+
|
|
89
|
+
### F2. Do one thing
|
|
90
|
+
|
|
91
|
+
A function does one thing when you cannot extract another function from it with a name that is not a restatement of its body. If `compute_invoice` contains a 10-line block that you could meaningfully call `apply_discount`, the original was doing more than one thing.
|
|
92
|
+
|
|
93
|
+
### F3. One level of abstraction per function
|
|
94
|
+
|
|
95
|
+
Mixing levels is the most common subtle defect. Do not put an HTTP call, a SQL query, a regex parse, and a business rule in the same function — those are four levels.
|
|
96
|
+
|
|
97
|
+
**Bad:**
|
|
98
|
+
```text
|
|
99
|
+
renderUserReport(userId):
|
|
100
|
+
connection = openDatabaseConnection()
|
|
101
|
+
row = queryUserRow(connection, userId)
|
|
102
|
+
displayName = row.firstName + " " + row.lastName
|
|
103
|
+
markup = "<h1>" + displayName + "</h1>"
|
|
104
|
+
return markup
|
|
105
|
+
```
|
|
106
|
+
Four levels: connection, query, formatting, presentation.
|
|
107
|
+
|
|
108
|
+
**Good:**
|
|
109
|
+
```text
|
|
110
|
+
renderUserReport(userId):
|
|
111
|
+
user = userRepository.findById(userId)
|
|
112
|
+
return userReportView.render(user)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### F4. Step-down rule
|
|
116
|
+
|
|
117
|
+
Read a file top-to-bottom; each function is followed by functions one level of abstraction below. Callers above callees. Confirmed by Uncle Bob himself on X.
|
|
118
|
+
|
|
119
|
+
### F5. Few arguments
|
|
120
|
+
|
|
121
|
+
Zero is best. One is fine. Two is OK. Three "should be avoided." Four or more "requires very special justification" — usually means you should pass a config object.
|
|
122
|
+
|
|
123
|
+
At five parameters, stop and extract a request/config object: record, struct, DTO, or equivalent.
|
|
124
|
+
|
|
125
|
+
### F6. No flag arguments
|
|
126
|
+
|
|
127
|
+
A boolean parameter that switches behavior is always wrong. Split into two functions.
|
|
128
|
+
|
|
129
|
+
**Bad:**
|
|
130
|
+
```text
|
|
131
|
+
render(invoice, asHtml):
|
|
132
|
+
if asHtml:
|
|
133
|
+
...
|
|
134
|
+
else:
|
|
135
|
+
...
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**Good:**
|
|
139
|
+
```text
|
|
140
|
+
renderInvoiceHtml(invoice)
|
|
141
|
+
renderInvoicePdf(invoice)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The same applies to `mode="x"` string enums when the mode changes behavior. If `mode` parameterizes data (locale, currency), it's fine. If it parameterizes *which function runs*, split.
|
|
145
|
+
|
|
146
|
+
### F7. No output arguments / Command-Query Separation
|
|
147
|
+
|
|
148
|
+
A function either returns a value (query) or has a side effect (command). Never both.
|
|
149
|
+
|
|
150
|
+
**Bad:**
|
|
151
|
+
```text
|
|
152
|
+
save(record) -> boolean
|
|
153
|
+
// Returns true if saved, false if record was not found.
|
|
154
|
+
```
|
|
155
|
+
What does the bool mean? Success? Found-ness? The caller can't tell.
|
|
156
|
+
|
|
157
|
+
**Good:**
|
|
158
|
+
```text
|
|
159
|
+
save(record)
|
|
160
|
+
recordExists(recordId) -> boolean
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### F8. No side effects in queries
|
|
164
|
+
|
|
165
|
+
A getter-style, finder-style, or predicate-style function must not mutate state. If it caches, log the cache write at debug level; do not change observable behavior.
|
|
166
|
+
|
|
167
|
+
### F9. Prefer exceptions to return codes
|
|
168
|
+
|
|
169
|
+
`if save(x):` is a code smell. Either save succeeds (returns nothing) or it raises (`InvoiceSaveError`). Return codes proliferate up the call stack and get forgotten; exceptions can't be ignored silently.
|
|
170
|
+
|
|
171
|
+
### F10. Duplication is the root evil
|
|
172
|
+
|
|
173
|
+
If two functions share a non-trivial block, extract it. But — see [dry-kiss-yagni.md](dry-kiss-yagni.md) for when this is wrong (Sandi Metz's "wrong abstraction" caveat).
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Self-check for naming and functions
|
|
178
|
+
|
|
179
|
+
Before you ship code:
|
|
180
|
+
|
|
181
|
+
1. Do all names answer "what does this represent" without a comment?
|
|
182
|
+
2. Are functions ≤20 lines?
|
|
183
|
+
3. Are functions doing one thing? (Can you extract another function with a non-restating name? If yes, you're doing more than one.)
|
|
184
|
+
4. Are mixed abstraction levels eliminated?
|
|
185
|
+
5. Are there any functions with >4 parameters? Extract a config object.
|
|
186
|
+
6. Are there boolean flag arguments? Split.
|
|
187
|
+
7. Do any functions both return a value *and* mutate state in a way callers depend on? Split.
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Review-Mode Checklist
|
|
2
|
+
|
|
3
|
+
When the user asks you to **review, audit, critique, or rate code** (rather than write it), follow this structured walk-through. Do not edit the code unless asked. Produce a findings report.
|
|
4
|
+
|
|
5
|
+
## Contents
|
|
6
|
+
|
|
7
|
+
- Output format
|
|
8
|
+
- Pre-flight: is this a refactor or a rewrite?
|
|
9
|
+
- Walk order
|
|
10
|
+
- Section A: naming and functions
|
|
11
|
+
- Section B: comments and formatting
|
|
12
|
+
- Section C: SOLID
|
|
13
|
+
- Section D: DRY, KISS, YAGNI
|
|
14
|
+
- Section E: AI failure modes
|
|
15
|
+
- What to do with each finding
|
|
16
|
+
- When the review is contested
|
|
17
|
+
- What this review does not do
|
|
18
|
+
|
|
19
|
+
## Output format
|
|
20
|
+
|
|
21
|
+
Use this template exactly. The headings make findings easy to triage.
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
# Code review: <file or scope>
|
|
25
|
+
|
|
26
|
+
## Summary
|
|
27
|
+
<2–3 sentence verdict: ship / needs work / rewrite>
|
|
28
|
+
Counts: <N> critical, <M> important, <K> nits (must equal the findings listed below)
|
|
29
|
+
|
|
30
|
+
## Critical findings
|
|
31
|
+
<must-fix before merge; omit this heading if none>
|
|
32
|
+
- `<file>:<line>` — <tag>: <what's wrong> [`<quoted code or behavior>`]. Fix: <concrete change>.
|
|
33
|
+
<continuation line only when the fix is code-sized>
|
|
34
|
+
|
|
35
|
+
## Important findings
|
|
36
|
+
<should fix but not blocking; omit if none>
|
|
37
|
+
- ...
|
|
38
|
+
|
|
39
|
+
## Nits
|
|
40
|
+
<style, naming, minor structure; max 3, each with a fix; omit if none>
|
|
41
|
+
- ...
|
|
42
|
+
|
|
43
|
+
## What's good
|
|
44
|
+
<0–3 genuine, specific positives; omit on a clean review — do not manufacture praise>
|
|
45
|
+
|
|
46
|
+
## Coverage
|
|
47
|
+
One line per section: the findings it produced, or `clean` (walked it, found nothing). A blank section is an unbacked claim, not a pass — fill it before delivering.
|
|
48
|
+
- Section A (naming & functions): <findings, or `clean`>
|
|
49
|
+
- Section B (comments & formatting): <findings, or `clean`>
|
|
50
|
+
- Section C (SOLID): <findings, or `clean`>
|
|
51
|
+
- Section D (DRY/KISS/YAGNI): <findings, or `clean`>
|
|
52
|
+
- Section E (AI failure modes): <findings, or `clean`>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Severity:
|
|
56
|
+
- **Critical** — security, correctness, data loss, swallowed exceptions, hardcoded "success" returns.
|
|
57
|
+
- **Important** — design defects with maintenance cost: SOLID violations, premature abstractions, parameter explosion, generic naming.
|
|
58
|
+
- **Nit** — style, single-letter names outside loops, missing docstring contracts on public APIs.
|
|
59
|
+
|
|
60
|
+
Every finding carries its quoted code or observed behavior and a named fix — that is what lets the author contest it; with no quote or no fix it is not a finding, so drop it. Report only counted findings: never an estimated quality score, "X% cleaner," or a maintainability index — no baseline exists, so the number would be invented.
|
|
61
|
+
|
|
62
|
+
## Pre-flight: is this a refactor or a rewrite?
|
|
63
|
+
|
|
64
|
+
Before walking the sections, classify the review:
|
|
65
|
+
|
|
66
|
+
- **Refactor review:** the user wants the code to be cleaner, not different. **Observable behavior must not change** — same inputs, same outputs, same exceptions, same side effects. If you'd suggest a change that alters behavior, mark it as a *separate finding* labelled "Behavior change — confirm with author" and do not bundle it with refactor recommendations. Refactoring is *"a change made to the internal structure of software... without changing its observable behavior"* (Fowler, *Refactoring*).
|
|
67
|
+
- **Code-review for correctness:** the user wants you to find bugs. Behavior changes are in scope. Flag them at Critical severity if they affect the contract.
|
|
68
|
+
|
|
69
|
+
If you can't tell which one the user wants, ask before writing the review.
|
|
70
|
+
|
|
71
|
+
## Walk order
|
|
72
|
+
|
|
73
|
+
### Section A — naming and functions
|
|
74
|
+
|
|
75
|
+
Pull [naming-and-functions.md](naming-and-functions.md) if you need source citations.
|
|
76
|
+
|
|
77
|
+
1. Scan all identifiers. Flag generic ones: `data`, `result`, `item`, `temp`, `value`, `obj`, `info`, `helper`, `manager`, `utils`, `handle_*`, `process_*`, `do_*` without qualifier.
|
|
78
|
+
2. For each function: lines ≤20? params ≤4? one thing? one level of abstraction? Flag violations.
|
|
79
|
+
3. Flag boolean flag arguments.
|
|
80
|
+
4. Flag functions that both return value *and* mutate observable state ambiguously (CQS violation).
|
|
81
|
+
5. Flag getter-style or predicate-style functions that mutate.
|
|
82
|
+
|
|
83
|
+
### Section B — comments and formatting
|
|
84
|
+
|
|
85
|
+
Pull [comments-and-formatting.md](comments-and-formatting.md) if needed.
|
|
86
|
+
|
|
87
|
+
1. Flag every comment that paraphrases the code below it.
|
|
88
|
+
2. Flag commented-out code blocks.
|
|
89
|
+
3. Flag step-number, "First...", or "Then..." scaffolding comments.
|
|
90
|
+
4. Flag docstrings that restate the signature with no contract.
|
|
91
|
+
5. Flag style inconsistencies with the surrounding file (casing, quoting, import order).
|
|
92
|
+
|
|
93
|
+
### Section C — SOLID
|
|
94
|
+
|
|
95
|
+
Pull [solid.md](solid.md) if needed.
|
|
96
|
+
|
|
97
|
+
1. (SRP) Any class with methods serving two unrelated stakeholder groups?
|
|
98
|
+
2. (OCP) Conditional or switch dispatch on a type tag that grew with the codebase?
|
|
99
|
+
3. (LSP) Any subclass with an unimplemented/unsupported-operation failure, strengthened preconditions, or weakened postconditions?
|
|
100
|
+
4. (ISP) Any interface where the concrete client uses only a subset of methods?
|
|
101
|
+
5. (DIP) High-level module importing a concrete from a low-level module? Abstractions living in the same package as the concrete?
|
|
102
|
+
|
|
103
|
+
### Section D — DRY, KISS, YAGNI
|
|
104
|
+
|
|
105
|
+
Pull [dry-kiss-yagni.md](dry-kiss-yagni.md) if needed.
|
|
106
|
+
|
|
107
|
+
1. (DRY) ≥5-line duplicated blocks. Confirm it's knowledge duplication before recommending extraction.
|
|
108
|
+
2. (DRY-Metz) Wrong abstractions: per-caller branches and special-case flags accumulating in a shared function.
|
|
109
|
+
3. (KISS) Any function with cyclomatic >10 or nesting >5? (Estimate from branches and loops; you don't need exact metrics.)
|
|
110
|
+
4. (YAGNI) Optional parameters never called, config flags with one path, abstractions with one implementation, wrappers around libraries that "make them swappable."
|
|
111
|
+
|
|
112
|
+
### Section E — AI failure modes (highest leverage)
|
|
113
|
+
|
|
114
|
+
Pull [ai-failure-modes.md](ai-failure-modes.md) for every check here.
|
|
115
|
+
|
|
116
|
+
1. Any catch-all error handler that swallows without recovery? Critical.
|
|
117
|
+
2. Any defensive guards for types/values the system already excludes — *inside* a trust boundary? (Validation of external or untrusted input at the boundary is not a defensive guard; do not flag it.)
|
|
118
|
+
3. Any premature abstraction — interface or factory with one implementation?
|
|
119
|
+
4. Any comment pollution — line-by-line restating, step-number scaffolding, or documentation comments that paraphrase signatures?
|
|
120
|
+
5. Any duplication of logic that already exists in a helper in the same repo?
|
|
121
|
+
6. Any imports or library methods you should verify exist in the installed version?
|
|
122
|
+
7. Any generic naming (cross-check with Section A).
|
|
123
|
+
8. Any long function mixing concerns (cross-check with Section A).
|
|
124
|
+
9. Any 5+ parameter functions without a config object (cross-check with Section A).
|
|
125
|
+
10. Any inconsistency with surrounding file style (cross-check with Section B).
|
|
126
|
+
11. Any dead code, unused imports, unreachable branches, half-implementations?
|
|
127
|
+
12. **Any hardcoded "success" returns, mock fixtures, fake values in production code?** Critical.
|
|
128
|
+
13. Any code that looks copy-pasted from a similar function (off-by-one, wrong null semantic)?
|
|
129
|
+
14. Any speculative configurability — flags, env vars, optional params without callers?
|
|
130
|
+
15. **Any "simplification" that deleted boundary validation, or a cleanup path (`finally`/`close`/`defer`/context-manager) the contract relied on?** That's a behavior change, not cleanup. Critical.
|
|
131
|
+
|
|
132
|
+
## What to do with each finding
|
|
133
|
+
|
|
134
|
+
A finding must name its fix — a code change OR a specific structural action. "Nameable" is the bar, not "codeable." No named fix means it stays vague unease, not a finding — drop it.
|
|
135
|
+
|
|
136
|
+
- ❌ "This error handling could perhaps be more specific." (no named replacement — drop it)
|
|
137
|
+
- ✅ "`L42 except Exception` swallows the DB error → catch `OperationalError`, let the rest propagate."
|
|
138
|
+
- ✅ "`L88–140 processOrder` mixes validation, pricing, persistence → extract `validate()` and `price()`."
|
|
139
|
+
|
|
140
|
+
For each finding: quote the offending code (file + line), name the principle or AI failure mode in `references/`, give the fix (code if small, a named structural action if not), and assign severity (Critical / Important / Nit).
|
|
141
|
+
|
|
142
|
+
## When the review is contested
|
|
143
|
+
|
|
144
|
+
If the user pushes back on a finding, cite the source from the relevant `references/` file. The rules trace to primary sources (Uncle Bob, Fowler, Hunt & Thomas, McCabe, Metz) and published 2024–2026 research on LLM code generation. If the user has a context-specific reason to override, record it as an inline comment that names **the principle, the reason, and a revisit trigger** — e.g. `// clean-code exception: 4-arg ceiling — config DTO, all fields required at construction; revisit when an optional field appears.` (the prefix is illustrative, not a required tag). On a later pass a well-formed marker downgrades the finding to *Documented exception* — don't re-flag it; a marker with **no revisit trigger is itself a finding**, since an exception with no exit is just deferred debt. Name the principle, not a rule number — a number is meaningless to a future reader.
|
|
145
|
+
|
|
146
|
+
## What this review does not do
|
|
147
|
+
|
|
148
|
+
- Run linters or formatters. That's tooling.
|
|
149
|
+
- Execute the code or run tests. Add a finding instead: *"No tests for the new `charge` path — recommend adding."*
|
|
150
|
+
- Enforce language-specific style (Black, Prettier, PHPCS). Defer to the project's style tooling unless the user explicitly asks.
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# SOLID — the five principles
|
|
2
|
+
|
|
3
|
+
Source: Robert C. Martin. The five principles were collected on Uncle Bob's "Principles of OOD" page on objectmentor.com (mirrored at butunclebob.com) and updated on blog.cleancoder.com. Original papers from *C++ Report* circa 1995–1996.
|
|
4
|
+
|
|
5
|
+
## Contents
|
|
6
|
+
|
|
7
|
+
- S: Single Responsibility Principle
|
|
8
|
+
- O: Open/Closed Principle
|
|
9
|
+
- L: Liskov Substitution Principle
|
|
10
|
+
- I: Interface Segregation Principle
|
|
11
|
+
- D: Dependency Inversion Principle
|
|
12
|
+
- How AI-generated code typically breaks SOLID
|
|
13
|
+
- Self-check for SOLID
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## S — Single Responsibility Principle
|
|
18
|
+
|
|
19
|
+
**Definition (Martin 2014, hardened from the original).** *"A module should be responsible to one, and only one, actor."*
|
|
20
|
+
|
|
21
|
+
Older form: "A class should have only one reason to change."
|
|
22
|
+
|
|
23
|
+
Source: blog.cleancoder.com — SRP, 2014.
|
|
24
|
+
|
|
25
|
+
### Why
|
|
26
|
+
|
|
27
|
+
The axis is *people*. Different stakeholders (Accounting, HR, DBA) want different things from the same class. When their needs change, they edit the same file, conflict, and break each other.
|
|
28
|
+
|
|
29
|
+
### Smells to flag
|
|
30
|
+
|
|
31
|
+
- One class contains methods touching unrelated subsystems (persistence + presentation + business rules).
|
|
32
|
+
- Methods on the class serve disjoint stakeholder groups.
|
|
33
|
+
- Git history shows two distinct clusters of co-changing methods inside one class.
|
|
34
|
+
|
|
35
|
+
### Common misinterpretation
|
|
36
|
+
|
|
37
|
+
*"A class should do one thing."* No. SRP is about **cohesion around an actor**, not method count. A 12-method `InvoiceRepository` answerable only to the data-access layer satisfies SRP. A 3-method class with one HTTP call, one Jinja render, and one DB write does not.
|
|
38
|
+
|
|
39
|
+
### Bad
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
EmployeeReport
|
|
43
|
+
calculatePay() // Accounting
|
|
44
|
+
reportHours() // HR
|
|
45
|
+
save() // Data storage owner
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Good
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
PayCalculator // Accounting
|
|
52
|
+
HoursReporter // HR
|
|
53
|
+
EmployeeRepository // Data storage owner
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## O — Open/Closed Principle
|
|
59
|
+
|
|
60
|
+
**Definition.** *"Software entities (classes, modules, functions) should be open for extension, but closed for modification."*
|
|
61
|
+
|
|
62
|
+
Originally Bertrand Meyer (1988, *Object-Oriented Software Construction*); Martin refocused it on polymorphic abstraction rather than implementation inheritance.
|
|
63
|
+
|
|
64
|
+
Source: blog.cleancoder.com — OCP, 2014; Martin's 1996 paper PDF (Duke mirror).
|
|
65
|
+
|
|
66
|
+
### Why
|
|
67
|
+
|
|
68
|
+
Protect stable high-level policy from churn in low-level variants. New behavior should arrive as new code, not edits to working code.
|
|
69
|
+
|
|
70
|
+
### Smells to flag
|
|
71
|
+
|
|
72
|
+
- Branch dispatching on a type tag or runtime type check — every new type requires editing the same function.
|
|
73
|
+
- Adding a feature requires modifying N existing files instead of adding one.
|
|
74
|
+
- `match`/`enum` switches that cross module boundaries (policy reaching into details).
|
|
75
|
+
|
|
76
|
+
### Common misinterpretation
|
|
77
|
+
|
|
78
|
+
*"Never modify code."* The principle is that *modules containing high-level policy* should not be modified to accommodate new variants. Leaf code changes freely.
|
|
79
|
+
|
|
80
|
+
### Bad
|
|
81
|
+
|
|
82
|
+
```text
|
|
83
|
+
export(record, kind):
|
|
84
|
+
if kind == "pdf": return toPdf(record)
|
|
85
|
+
if kind == "csv": return toCsv(record)
|
|
86
|
+
if kind == "json": return toJson(record)
|
|
87
|
+
// adding "xml" requires editing this function
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Good
|
|
91
|
+
|
|
92
|
+
```text
|
|
93
|
+
exporters = {
|
|
94
|
+
"pdf": toPdf,
|
|
95
|
+
"csv": toCsv,
|
|
96
|
+
"json": toJson,
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export(record, kind):
|
|
100
|
+
return exporters[kind](record)
|
|
101
|
+
// adding "xml" is one line in the table
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## L — Liskov Substitution Principle
|
|
107
|
+
|
|
108
|
+
**Definition (Liskov & Wing, 1994).** *"If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2, then S is a subtype of T."*
|
|
109
|
+
|
|
110
|
+
Source: Martin's LSP paper PDF (LaBRI mirror).
|
|
111
|
+
|
|
112
|
+
### Why
|
|
113
|
+
|
|
114
|
+
Substitutability. Callers written against a base type must continue to work when handed a subtype — otherwise polymorphism leaks abstraction.
|
|
115
|
+
|
|
116
|
+
### Smells to flag
|
|
117
|
+
|
|
118
|
+
- A subclass overrides a method to signal "not implemented" or "unsupported operation."
|
|
119
|
+
- A subclass **strengthens preconditions** (rejects inputs the parent accepts).
|
|
120
|
+
- A subclass **weakens postconditions** (returns something the parent guarantees against).
|
|
121
|
+
- Callers perform runtime subtype checks to decide whether to call a method.
|
|
122
|
+
|
|
123
|
+
### Common misinterpretation
|
|
124
|
+
|
|
125
|
+
*"Subclasses must have the same methods."* That's signature compatibility, which is just type-checking. LSP is **behavioral**:
|
|
126
|
+
- Preconditions can only **weaken** in the subtype.
|
|
127
|
+
- Postconditions and invariants can only **strengthen**.
|
|
128
|
+
- Parameter types are contravariant; return types covariant.
|
|
129
|
+
|
|
130
|
+
### The Rectangle/Square classic
|
|
131
|
+
|
|
132
|
+
```text
|
|
133
|
+
Rectangle
|
|
134
|
+
setWidth(width)
|
|
135
|
+
setHeight(height)
|
|
136
|
+
area()
|
|
137
|
+
|
|
138
|
+
Square extends Rectangle
|
|
139
|
+
setWidth(width):
|
|
140
|
+
this.width = width
|
|
141
|
+
this.height = width // invariant: width == height
|
|
142
|
+
setHeight(height):
|
|
143
|
+
this.width = height // invariant: width == height
|
|
144
|
+
this.height = height
|
|
145
|
+
```
|
|
146
|
+
A caller holding a `Rectangle` reference does `r.set_width(5); r.set_height(4); assert r.area() == 20`. With a `Square`, the assertion fails — LSP violated.
|
|
147
|
+
|
|
148
|
+
The fix is *not* to fix the methods. The fix is that `Square is-not-a Rectangle` in the behavioral sense. Compose, don't inherit.
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## I — Interface Segregation Principle
|
|
153
|
+
|
|
154
|
+
**Definition.** *"Clients should not be forced to depend on methods they do not use."* Equivalently: many client-specific interfaces beat one general-purpose interface.
|
|
155
|
+
|
|
156
|
+
Source: Martin's 1996 ISP paper, catalogued at butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod.
|
|
157
|
+
|
|
158
|
+
### Why
|
|
159
|
+
|
|
160
|
+
Fat interfaces create transitive coupling. Clients are dragged into recompiles and test-fixtures for methods they never call.
|
|
161
|
+
|
|
162
|
+
### Smells to flag
|
|
163
|
+
|
|
164
|
+
- A `Service` / `Manager` / `Repository` interface with 10+ methods, where any given caller uses one or two.
|
|
165
|
+
- Implementations that stub half the methods with no-op bodies, null/empty placeholders, or unimplemented failures (usually co-occurs with an LSP violation).
|
|
166
|
+
- One mock object reconfigured differently across tests because the interface is too broad.
|
|
167
|
+
|
|
168
|
+
### Common misinterpretation
|
|
169
|
+
|
|
170
|
+
*"Make interfaces small."* As a count rule, no. ISP is **client-centric** — segregation is driven by *the set of methods a particular client uses*, not by an arbitrary method-count ceiling. Two clients with identical method needs can share one interface even if it has 20 methods.
|
|
171
|
+
|
|
172
|
+
### Bad
|
|
173
|
+
|
|
174
|
+
```text
|
|
175
|
+
UserService
|
|
176
|
+
create(...)
|
|
177
|
+
read(...)
|
|
178
|
+
update(...)
|
|
179
|
+
delete(...)
|
|
180
|
+
email(...)
|
|
181
|
+
notify(...)
|
|
182
|
+
audit(...)
|
|
183
|
+
export(...)
|
|
184
|
+
```
|
|
185
|
+
The audit logger only needs `audit`. It now depends transitively on the email and export subsystems.
|
|
186
|
+
|
|
187
|
+
### Good
|
|
188
|
+
|
|
189
|
+
```text
|
|
190
|
+
UserAuditor
|
|
191
|
+
audit(...)
|
|
192
|
+
|
|
193
|
+
UserNotifier
|
|
194
|
+
notify(...)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Implementations can satisfy multiple protocols. Callers depend only on what they use.
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## D — Dependency Inversion Principle
|
|
202
|
+
|
|
203
|
+
**Definition (verbatim, two clauses).**
|
|
204
|
+
*(a) High-level modules should not depend on low-level modules. Both should depend on abstractions.*
|
|
205
|
+
*(b) Abstractions should not depend on details. Details should depend on abstractions.*
|
|
206
|
+
|
|
207
|
+
Source: Martin's 1996 *C++ Report* paper, archived at Wayback / objectmentor.com.
|
|
208
|
+
|
|
209
|
+
### Why
|
|
210
|
+
|
|
211
|
+
Control the direction of the import graph. Policy must not transitively `import` mechanism, or policy becomes un-reusable and untestable.
|
|
212
|
+
|
|
213
|
+
### Smells to flag
|
|
214
|
+
|
|
215
|
+
- A high-level module imports a concrete low-level client inside business logic.
|
|
216
|
+
- A constructor that `new`/instantiates concrete collaborators instead of accepting them as parameters.
|
|
217
|
+
- Abstractions defined in the *low-level* package (the interface lives next to its database or service implementation) — ownership reversed. The interface should live in the **client's** package.
|
|
218
|
+
- Function signatures typed against concrete classes instead of interfaces, protocols, or abstract contracts.
|
|
219
|
+
|
|
220
|
+
### Common misinterpretation
|
|
221
|
+
|
|
222
|
+
*"DIP means use a DI container."* No. DIP is about **the direction of source-code dependencies**. You can satisfy DIP with plain constructor injection and no framework; you can violate DIP while using Spring.
|
|
223
|
+
|
|
224
|
+
### Bad
|
|
225
|
+
|
|
226
|
+
```text
|
|
227
|
+
// billing/charge — high-level policy
|
|
228
|
+
import SqlUserRepository // concrete import
|
|
229
|
+
|
|
230
|
+
chargeUser(userId, amount):
|
|
231
|
+
repository = new SqlUserRepository() // concrete instantiation
|
|
232
|
+
user = repository.get(userId)
|
|
233
|
+
...
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Good
|
|
237
|
+
|
|
238
|
+
```text
|
|
239
|
+
// billing/user-repository — abstraction lives WITH the client (billing)
|
|
240
|
+
UserRepository
|
|
241
|
+
get(userId) -> User
|
|
242
|
+
|
|
243
|
+
// billing/charge
|
|
244
|
+
chargeUser(userId, amount, repository: UserRepository):
|
|
245
|
+
user = repository.get(userId)
|
|
246
|
+
...
|
|
247
|
+
|
|
248
|
+
// sql/user-repository — detail depends on the abstraction
|
|
249
|
+
SqlUserRepository satisfies UserRepository
|
|
250
|
+
get(userId) -> User
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
The import arrows go: `sql → billing` (detail → abstraction). They do not go `billing → sql`.
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## How AI-generated code typically breaks SOLID
|
|
258
|
+
|
|
259
|
+
Mapped to the principle each breaks:
|
|
260
|
+
|
|
261
|
+
1. **God-module** from "do everything in one file" prompts — SRP + DIP + usually OCP.
|
|
262
|
+
2. **Type-tag dispatch chains** (`if kind == "pdf": ...`) — OCP.
|
|
263
|
+
3. **Unsupported-operation stubs in subclasses** when asked to "implement only the methods we need" — LSP + ISP.
|
|
264
|
+
4. **Concrete SDK/client imports at module load time** — DIP, hard to test without patching the runtime.
|
|
265
|
+
5. **Mega-`Service` interfaces** with create/read/update/delete/email/notify/audit/export — ISP, usually SRP too.
|
|
266
|
+
6. **Silent precondition strengthening on override** — defensive-looking, breaks LSP because callers holding the base type now crash on previously-valid inputs.
|
|
267
|
+
7. **Invariant-breaking "convenience" subclasses** (e.g., `ReadOnlyList(list)` overriding `append` to no-op) — LSP.
|
|
268
|
+
8. **Inverted ownership of abstractions** — putting the interface/protocol/abstract contract in the same file as the concrete implementation. Cosmetic DIP fix, real dependency graph unchanged.
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## Self-check for SOLID
|
|
273
|
+
|
|
274
|
+
Before you ship code:
|
|
275
|
+
|
|
276
|
+
1. (SRP) Does any class in the diff answer to more than one stakeholder group?
|
|
277
|
+
2. (OCP) Does any change require a type-tag branch added to an existing function? Could it be data-driven (registry/strategy) instead?
|
|
278
|
+
3. (LSP) Does any new subclass signal "not implemented", tighten preconditions, or weaken postconditions?
|
|
279
|
+
4. (ISP) Does any interface have a method your concrete client doesn't use?
|
|
280
|
+
5. (DIP) Does the high-level package import the low-level concrete? Where do new abstractions live — with the client or with the implementation?
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Sources
|
|
2
|
+
|
|
3
|
+
Central bibliography for `clean-code-guard`. Other reference files use source
|
|
4
|
+
names instead of inline URLs so rule guidance stays readable.
|
|
5
|
+
|
|
6
|
+
## Contents
|
|
7
|
+
|
|
8
|
+
- Classic clean code and design references
|
|
9
|
+
- LLM code-generation research and field reports
|
|
10
|
+
- Metrics and verification references
|
|
11
|
+
|
|
12
|
+
## Classic Clean Code And Design
|
|
13
|
+
|
|
14
|
+
- **Clean Code sample chapters**: https://ptgmedia.pearsoncmg.com/images/9780132350884/samplepages/9780132350884.pdf
|
|
15
|
+
- **Command Query Separation, Fowler**: https://martinfowler.com/bliki/CommandQuerySeparation.html
|
|
16
|
+
- **Refactoring, Fowler**: https://martinfowler.com/books/refactoring.html
|
|
17
|
+
- **YAGNI, Fowler**: https://martinfowler.com/bliki/Yagni.html
|
|
18
|
+
- **DRY, The Pragmatic Programmer excerpt**: https://media.pragprog.com/titles/tpp20/dry.pdf
|
|
19
|
+
- **The Wrong Abstraction, Sandi Metz**: https://sandimetz.com/blog/2016/1/20/the-wrong-abstraction
|
|
20
|
+
- **SOLID principles, Uncle Bob archive**: http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
|
|
21
|
+
- **SRP, Uncle Bob**: https://blog.cleancoder.com/uncle-bob/2014/05/08/SingleReponsibilityPrinciple.html
|
|
22
|
+
- **OCP, Uncle Bob**: https://blog.cleancoder.com/uncle-bob/2014/05/12/TheOpenClosedPrinciple.html
|
|
23
|
+
- **LSP, Liskov/Wing paper mirror**: https://www.labri.fr/perso/clement/enseignements/ao/LSP.pdf
|
|
24
|
+
- **DIP, Object Mentor archive**: https://web.archive.org/web/20150924054349/http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf
|
|
25
|
+
|
|
26
|
+
## LLM Code-Generation Research And Field Reports
|
|
27
|
+
|
|
28
|
+
- **GitClear AI code quality 2025**: https://www.gitclear.com/ai_assistant_code_quality_2025_research
|
|
29
|
+
- **Package Hallucinations, Spracklen et al., USENIX Security 2025**: https://www.usenix.org/system/files/conference/usenixsecurity25/sec25cycle1-prepub-742-spracklen.pdf
|
|
30
|
+
- **AI-Generated Code Considered Harmful**: https://arxiv.org/abs/2409.19182
|
|
31
|
+
- **A Deep Dive Into LLM Code Generation Mistakes**: https://arxiv.org/abs/2411.01414
|
|
32
|
+
- **Patterns for Reducing Friction in AI-Assisted Development, Fowler**: https://martinfowler.com/articles/reduce-friction-ai/
|
|
33
|
+
- **Claude Code issue 6984, mock data generation bias**: https://github.com/anthropics/claude-code/issues/6984
|
|
34
|
+
- **Karpathy on exception suppression**: https://x.com/karpathy/status/1976077806443569355
|
|
35
|
+
- **Code Needs Comments**: https://arxiv.org/html/2402.13013v1
|
|
36
|
+
- **Evaluating the Code Quality of AI-Assisted Code Generation Tools (Copilot, CodeWhisperer, ChatGPT)**: https://arxiv.org/abs/2304.10778
|
|
37
|
+
- **On Mitigating Code LLM Hallucinations with API Documentation**: https://arxiv.org/abs/2407.09726
|
|
38
|
+
- **LLM Hallucinations in Practical Code Generation (taxonomy)**: https://arxiv.org/abs/2409.20550
|
|
39
|
+
- **When Names Disappear: Revealing What LLMs Actually Understand About Code**: https://arxiv.org/abs/2510.03178
|
|
40
|
+
- **Neural Variable Name Repair**: https://arxiv.org/abs/2512.01141
|
|
41
|
+
- **Vibe Coding in Practice**: https://arxiv.org/abs/2512.11922
|
|
42
|
+
|
|
43
|
+
## Metrics And Verification
|
|
44
|
+
|
|
45
|
+
- **McCabe NIST 235r**: https://www.mccabe.com/pdf/mccabe-nist235r.pdf
|
|
46
|
+
- **Cognitive Complexity, SonarSource**: https://www.sonarsource.com/docs/CognitiveComplexity.pdf
|
|
47
|
+
- **ReSharper cyclomatic complexity threshold guidance**: https://github.com/JetBrains/resharper-cyclomatic-complexity/blob/master/docs/ThresholdGuidance.md
|