neo-skill 0.1.23 → 0.1.25
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/.shared/review-gate/README.md +237 -0
- package/.shared/review-gate/data/domains/api/anti_patterns.md +39 -0
- package/.shared/review-gate/data/domains/api/checks.csv +6 -0
- package/.shared/review-gate/data/domains/api/hardgate_candidates.csv +4 -0
- package/.shared/review-gate/data/domains/api/recipes.md +30 -0
- package/.shared/review-gate/data/domains/async/anti_patterns.md +7 -0
- package/.shared/review-gate/data/domains/async/checks.csv +4 -0
- package/.shared/review-gate/data/domains/async/hardgate_candidates.csv +2 -0
- package/.shared/review-gate/data/domains/async/recipes.md +8 -0
- package/.shared/review-gate/data/domains/complex/anti_patterns.md +39 -0
- package/.shared/review-gate/data/domains/complex/checks.csv +6 -0
- package/.shared/review-gate/data/domains/complex/hardgate_candidates.csv +5 -0
- package/.shared/review-gate/data/domains/complex/recipes.md +68 -0
- package/.shared/review-gate/data/domains/dep/anti_patterns.md +58 -0
- package/.shared/review-gate/data/domains/dep/checks.csv +6 -0
- package/.shared/review-gate/data/domains/dep/hardgate_candidates.csv +5 -0
- package/.shared/review-gate/data/domains/dep/recipes.md +89 -0
- package/.shared/review-gate/data/domains/doc/anti_patterns.md +7 -0
- package/.shared/review-gate/data/domains/doc/checks.csv +4 -0
- package/.shared/review-gate/data/domains/doc/hardgate_candidates.csv +2 -0
- package/.shared/review-gate/data/domains/doc/recipes.md +8 -0
- package/.shared/review-gate/data/domains/error/anti_patterns.md +7 -0
- package/.shared/review-gate/data/domains/error/checks.csv +4 -0
- package/.shared/review-gate/data/domains/error/hardgate_candidates.csv +2 -0
- package/.shared/review-gate/data/domains/error/recipes.md +10 -0
- package/.shared/review-gate/data/domains/layer/anti_patterns.md +97 -0
- package/.shared/review-gate/data/domains/layer/checks.csv +6 -0
- package/.shared/review-gate/data/domains/layer/hardgate_candidates.csv +6 -0
- package/.shared/review-gate/data/domains/layer/recipes.md +86 -0
- package/.shared/review-gate/data/domains/obs/anti_patterns.md +7 -0
- package/.shared/review-gate/data/domains/obs/checks.csv +3 -0
- package/.shared/review-gate/data/domains/obs/hardgate_candidates.csv +2 -0
- package/.shared/review-gate/data/domains/obs/recipes.md +7 -0
- package/.shared/review-gate/data/domains/perf/anti_patterns.md +7 -0
- package/.shared/review-gate/data/domains/perf/checks.csv +4 -0
- package/.shared/review-gate/data/domains/perf/hardgate_candidates.csv +2 -0
- package/.shared/review-gate/data/domains/perf/recipes.md +8 -0
- package/.shared/review-gate/data/domains/pure/anti_patterns.md +39 -0
- package/.shared/review-gate/data/domains/pure/checks.csv +6 -0
- package/.shared/review-gate/data/domains/pure/hardgate_candidates.csv +5 -0
- package/.shared/review-gate/data/domains/pure/recipes.md +47 -0
- package/.shared/review-gate/data/domains/sec/anti_patterns.md +7 -0
- package/.shared/review-gate/data/domains/sec/checks.csv +4 -0
- package/.shared/review-gate/data/domains/sec/hardgate_candidates.csv +3 -0
- package/.shared/review-gate/data/domains/sec/recipes.md +8 -0
- package/.shared/review-gate/data/domains/test/anti_patterns.md +7 -0
- package/.shared/review-gate/data/domains/test/checks.csv +4 -0
- package/.shared/review-gate/data/domains/test/hardgate_candidates.csv +2 -0
- package/.shared/review-gate/data/domains/test/recipes.md +8 -0
- package/.shared/review-gate/data/domains/type/anti_patterns.md +7 -0
- package/.shared/review-gate/data/domains/type/checks.csv +4 -0
- package/.shared/review-gate/data/domains/type/hardgate_candidates.csv +2 -0
- package/.shared/review-gate/data/domains/type/recipes.md +8 -0
- package/.shared/review-gate/data/domains/ui/anti_patterns.md +7 -0
- package/.shared/review-gate/data/domains/ui/checks.csv +4 -0
- package/.shared/review-gate/data/domains/ui/hardgate_candidates.csv +2 -0
- package/.shared/review-gate/data/domains/ui/recipes.md +8 -0
- package/.shared/review-gate/data/reasoning/review-reasoning.csv +16 -0
- package/.shared/review-gate/data/templates/evidence_schema.md +73 -0
- package/.shared/review-gate/data/templates/finding.md +33 -0
- package/.shared/review-gate/data/templates/report.md +41 -0
- package/.shared/review-gate/review-system/MASTER.md +57 -0
- package/.shared/review-gate/review-system/stacks/nextjs.md +43 -0
- package/.shared/review-gate/review-system/stacks/node.md +43 -0
- package/.shared/review-gate/review-system/stacks/react.md +36 -0
- package/.shared/review-gate/scripts/engine/__init__.py +8 -0
- package/.shared/review-gate/scripts/engine/composer.py +183 -0
- package/.shared/review-gate/scripts/engine/persist.py +111 -0
- package/.shared/review-gate/scripts/engine/router.py +179 -0
- package/.shared/review-gate/scripts/engine/scorer.py +92 -0
- package/.shared/review-gate/scripts/review.py +454 -0
- package/.shared/review-gate/scripts/signals/__init__.py +19 -0
- package/.shared/review-gate/scripts/signals/api_surface.py +201 -0
- package/.shared/review-gate/scripts/signals/complexity_scanner.py +103 -0
- package/.shared/review-gate/scripts/signals/diff_collector.py +182 -0
- package/.shared/review-gate/scripts/signals/graph_builder.py +200 -0
- package/.shared/review-gate/scripts/signals/layer_classifier.py +194 -0
- package/.shared/review-gate/scripts/signals/side_effect_scanner.py +69 -0
- package/.shared/review-gate/scripts/signals/test_runner.py +82 -0
- package/package.json +1 -1
- package/skills/skill-creator/skillspec.json +10 -1
- package/src/skill_creator/core/engine.py +65 -1
- package/src/skill_creator/core/interview.py +1 -1
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# .shared/review-gate
|
|
2
|
+
|
|
3
|
+
Production-grade architecture/code anti-corruption review skill with modular, data-driven, searchable system.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
review-gate is NOT hard-gate. It focuses on:
|
|
8
|
+
- Architecture decisions and module boundaries
|
|
9
|
+
- Dependency direction and layer violations
|
|
10
|
+
- Side-effect isolation and testability
|
|
11
|
+
- Long-term maintainability and "slow decay" prevention
|
|
12
|
+
|
|
13
|
+
**Evidence-first**: Every finding is backed by concrete evidence (files, diff hunks, dependency traces).
|
|
14
|
+
|
|
15
|
+
## Architecture
|
|
16
|
+
|
|
17
|
+
### 3-Layer Design (aligned with skill-creator conventions)
|
|
18
|
+
|
|
19
|
+
1. **Data Layer (Domains Index)**
|
|
20
|
+
- Split knowledge into 14 domains: layer/dep/api/pure/complex/error/obs/type/async/ui/perf/sec/doc/test
|
|
21
|
+
- Each domain contains: checks.csv, recipes.md, anti_patterns.md, hardgate_candidates.csv
|
|
22
|
+
|
|
23
|
+
2. **Reasoning Layer (Routing & Prioritization)**
|
|
24
|
+
- review-reasoning.csv maps signals → domains/checks/recipes with weights
|
|
25
|
+
- Supports layered overrides (paths > packages > stacks > MASTER)
|
|
26
|
+
|
|
27
|
+
3. **Runtime Layer (Analyzers + Router + Composer)**
|
|
28
|
+
- Signal analyzers: diff, dependency graph, layer classification, API surface, side-effects, complexity
|
|
29
|
+
- Router: loads overrides + reasoning rules, selects checks
|
|
30
|
+
- Composer: generates findings (JSON + Markdown) + reports
|
|
31
|
+
|
|
32
|
+
## Prerequisites
|
|
33
|
+
|
|
34
|
+
- Python 3.8+
|
|
35
|
+
- Git (for diff analysis)
|
|
36
|
+
- Node.js/TypeScript project (for dependency graph analysis)
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
### Basic Review
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
python3 .shared/review-gate/scripts/review.py --base-branch main
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### With Test Enforcement
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
python3 .shared/review-gate/scripts/review.py --ensure-tests-pass --base-branch main
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Focused Domain Search
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
python3 .shared/review-gate/scripts/review.py --domain layer --max-results 10
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Stack-Specific Review
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
python3 .shared/review-gate/scripts/review.py --stack nextjs --base-branch main
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Persist Override Rules
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
python3 .shared/review-gate/scripts/review.py --persist path --path src/domain/user
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Workflow
|
|
71
|
+
|
|
72
|
+
1. Creates branch: `review-gate/<YYYYMMDD>-<topic>-<ref>`
|
|
73
|
+
2. (Optional) Runs existing tests baseline
|
|
74
|
+
3. Extracts PR diff changeset
|
|
75
|
+
4. Builds impacted dependency subgraph
|
|
76
|
+
5. Generates signals (layer/dep/api/pure/complex/etc.)
|
|
77
|
+
6. Router selects & prioritizes checks
|
|
78
|
+
7. Composer generates findings + report
|
|
79
|
+
8. (Optional) Applies minimal fixes for blockers
|
|
80
|
+
9. (Optional) Reruns tests to ensure green
|
|
81
|
+
10. Outputs final report (Markdown + JSON)
|
|
82
|
+
|
|
83
|
+
## Domain Reference
|
|
84
|
+
|
|
85
|
+
### MVP Domains (Fully Implemented)
|
|
86
|
+
|
|
87
|
+
- **layer**: Layer violations, directory organization, dependency direction
|
|
88
|
+
- **dep**: Circular dependencies, coupling, dependency direction violations
|
|
89
|
+
- **api**: Public API design, exports management, breaking changes
|
|
90
|
+
- **pure**: Side-effect isolation, testability, pure function violations
|
|
91
|
+
- **complex**: Cognitive complexity, nesting, god functions
|
|
92
|
+
|
|
93
|
+
### Additional Domains (Pluggable Stubs)
|
|
94
|
+
|
|
95
|
+
- **error**: Error handling, error boundaries, error propagation
|
|
96
|
+
- **obs**: Logging, observability, console usage
|
|
97
|
+
- **type**: Type safety, type definitions, type exports
|
|
98
|
+
- **async**: Async patterns, promise handling, race conditions
|
|
99
|
+
- **ui**: React patterns, component design, rendering optimization
|
|
100
|
+
- **perf**: Performance anti-patterns, resource leaks, blocking operations
|
|
101
|
+
- **sec**: Security risks, XSS, injection, validation
|
|
102
|
+
- **doc**: Documentation quality, API docs, comments
|
|
103
|
+
- **test**: Test coverage, test quality, test maintainability
|
|
104
|
+
|
|
105
|
+
## Output Formats
|
|
106
|
+
|
|
107
|
+
### Evidence Schema (JSON)
|
|
108
|
+
|
|
109
|
+
Every finding follows this schema:
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"id": "RG-LAYER-001",
|
|
114
|
+
"severity": "BLOCKER",
|
|
115
|
+
"area": "LAYER",
|
|
116
|
+
"checklist_ref": "C-LAYER-01",
|
|
117
|
+
"title": "Domain layer imports from presentation",
|
|
118
|
+
"status": "OPEN",
|
|
119
|
+
"confidence": "HIGH",
|
|
120
|
+
"evidence": {
|
|
121
|
+
"files": [{"path": "src/domain/user.ts", "diff_hunks": ["..."]}],
|
|
122
|
+
"dependency_trace": {"chain": ["..."], "direction_violation": true}
|
|
123
|
+
},
|
|
124
|
+
"impact": ["ARCH", "MAINTAINABILITY"],
|
|
125
|
+
"blast_radius": "MODULE",
|
|
126
|
+
"risk_if_merge": "Violates dependency inversion...",
|
|
127
|
+
"proposed_fix": ["1. Extract shared types...", "2. Use dependency injection..."],
|
|
128
|
+
"acceptance_criteria": "Domain layer has no imports from presentation",
|
|
129
|
+
"automatable": "PARTIAL",
|
|
130
|
+
"hard_gate_candidate": {
|
|
131
|
+
"rule_idea": "Detect imports from domain/* to presentation/*",
|
|
132
|
+
"implementation_hint": "AST analysis + import path checking"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Report Structure
|
|
138
|
+
|
|
139
|
+
- **Summary**: Overview, changeset stats, signal summary
|
|
140
|
+
- **Blockers**: Critical findings that should prevent merge
|
|
141
|
+
- **Recommendations**: Important but non-blocking improvements
|
|
142
|
+
- **HardGateCandidates**: Automatable rules to add to hard-gate
|
|
143
|
+
- **Fix Commits**: Map of findings → commit hashes (if fixes applied)
|
|
144
|
+
|
|
145
|
+
## Layered Override System
|
|
146
|
+
|
|
147
|
+
Hierarchical precedence (highest to lowest):
|
|
148
|
+
|
|
149
|
+
1. `review-system/paths/*.md` - Path-specific overrides
|
|
150
|
+
2. `review-system/packages/<pkg>.md` - Package-specific overrides
|
|
151
|
+
3. `review-system/stacks/<stack>.md` - Stack-specific overrides
|
|
152
|
+
4. `review-system/MASTER.md` - Base configuration
|
|
153
|
+
|
|
154
|
+
Override files can modify:
|
|
155
|
+
- Check severity levels
|
|
156
|
+
- Allowlist exceptions
|
|
157
|
+
- Custom notes/rationale
|
|
158
|
+
- Domain weights
|
|
159
|
+
|
|
160
|
+
## Consistency with skill-creator
|
|
161
|
+
|
|
162
|
+
This skill follows the same conventions as skill-creator:
|
|
163
|
+
|
|
164
|
+
- **Directory layout**: `.shared/<skill>/` with `scripts/`, `data/`, standard structure
|
|
165
|
+
- **CLI pattern**: Similar to `scripts/search.py` with consistent flags and output formatting
|
|
166
|
+
- **Data organization**: CSV/JSON indexes in `data/`, hierarchical domain structure
|
|
167
|
+
- **Output formats**: ASCII/Markdown/JSON with consistent formatting
|
|
168
|
+
- **Reasoning rules**: CSV-based routing similar to `skill-reasoning.csv`
|
|
169
|
+
|
|
170
|
+
## Examples
|
|
171
|
+
|
|
172
|
+
### Example Command
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
python3 .shared/review-gate/scripts/review.py \
|
|
176
|
+
--base-branch main \
|
|
177
|
+
--stack nextjs \
|
|
178
|
+
--format markdown \
|
|
179
|
+
--ensure-tests-pass
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Example Output (Markdown)
|
|
183
|
+
|
|
184
|
+
```markdown
|
|
185
|
+
# Review Gate Report
|
|
186
|
+
|
|
187
|
+
**Branch**: review-gate/20260127-refactor-abc123
|
|
188
|
+
**Base**: main
|
|
189
|
+
**Stack**: nextjs
|
|
190
|
+
**Changeset**: 15 files, 234 additions, 89 deletions
|
|
191
|
+
|
|
192
|
+
## Summary
|
|
193
|
+
|
|
194
|
+
- 3 Blockers
|
|
195
|
+
- 7 Recommendations
|
|
196
|
+
- 2 HardGate Candidates
|
|
197
|
+
|
|
198
|
+
## Blockers
|
|
199
|
+
|
|
200
|
+
### [RG-LAYER-001] Domain layer imports from presentation
|
|
201
|
+
**Severity**: BLOCKER | **Confidence**: HIGH | **Area**: LAYER
|
|
202
|
+
|
|
203
|
+
**Evidence**:
|
|
204
|
+
- File: `src/domain/user/service.ts:12`
|
|
205
|
+
- Imports: `import { UserCard } from '@/presentation/components/UserCard'`
|
|
206
|
+
|
|
207
|
+
**Impact**: ARCH, MAINTAINABILITY
|
|
208
|
+
**Blast Radius**: MODULE
|
|
209
|
+
|
|
210
|
+
**Proposed Fix**:
|
|
211
|
+
1. Extract shared types to `src/types/user.ts`
|
|
212
|
+
2. Remove presentation dependency from domain
|
|
213
|
+
3. Use dependency injection for UI concerns
|
|
214
|
+
|
|
215
|
+
**Acceptance Criteria**: Domain layer has zero imports from presentation layer
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Recommendations
|
|
220
|
+
|
|
221
|
+
[... additional findings ...]
|
|
222
|
+
|
|
223
|
+
## HardGate Candidates
|
|
224
|
+
|
|
225
|
+
1. **Detect domain→presentation imports** (C-LAYER-01)
|
|
226
|
+
- Implementation: AST + import path analysis
|
|
227
|
+
- False positive risk: LOW
|
|
228
|
+
- Scope: TypeScript/JavaScript imports
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Notes
|
|
232
|
+
|
|
233
|
+
- **NOT a linter**: Focus is architecture, not style
|
|
234
|
+
- **Evidence-required**: All findings must have concrete proof
|
|
235
|
+
- **Minimal changes**: Code modifications are scoped and traceable
|
|
236
|
+
- **No new tests**: Only fixes to make existing tests pass
|
|
237
|
+
- **Deterministic**: Same input always produces same output
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# API Design Anti-Patterns
|
|
2
|
+
|
|
3
|
+
## Anti-Pattern: Index File Cascade
|
|
4
|
+
|
|
5
|
+
**Description**: Deeply nested index.ts files re-exporting everything
|
|
6
|
+
|
|
7
|
+
**Detection Signals**:
|
|
8
|
+
- index.ts files at 3+ levels
|
|
9
|
+
- Circular dependency warnings
|
|
10
|
+
- Import paths going through multiple index files
|
|
11
|
+
|
|
12
|
+
**Why It's Bad**:
|
|
13
|
+
- Creates tight coupling
|
|
14
|
+
- Causes circular dependencies
|
|
15
|
+
- Hard to track actual dependencies
|
|
16
|
+
|
|
17
|
+
**Fix**:
|
|
18
|
+
- Use package.json exports field
|
|
19
|
+
- Export from root index.ts only
|
|
20
|
+
- Remove intermediate index files
|
|
21
|
+
|
|
22
|
+
## Anti-Pattern: Kitchen Sink Module
|
|
23
|
+
|
|
24
|
+
**Description**: Single module exports everything
|
|
25
|
+
|
|
26
|
+
**Detection Signals**:
|
|
27
|
+
- Module with >20 exports
|
|
28
|
+
- Unrelated functionality in same file
|
|
29
|
+
- Module name is generic (utils, helpers, common)
|
|
30
|
+
|
|
31
|
+
**Why It's Bad**:
|
|
32
|
+
- Unclear module purpose
|
|
33
|
+
- Forces importing unused code
|
|
34
|
+
- Hard to maintain
|
|
35
|
+
|
|
36
|
+
**Fix**:
|
|
37
|
+
- Split into focused modules
|
|
38
|
+
- Group related functionality
|
|
39
|
+
- Use clear, specific names
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
id,title,severity,description,evidence_requirements,automatable
|
|
2
|
+
C-API-01,Deep index.ts files,RECOMMENDATION,Index files deeper than 2 levels risk circular deps,File paths,YES
|
|
3
|
+
C-API-02,Default export overuse,RECOMMENDATION,Default exports used outside framework requirements,Export analysis,PARTIAL
|
|
4
|
+
C-API-03,Breaking API change,BLOCKER,Public API modified without deprecation,API surface diff,PARTIAL
|
|
5
|
+
C-API-04,Undocumented public API,RECOMMENDATION,Public export lacks JSDoc/TSDoc,Export + comment analysis,YES
|
|
6
|
+
C-API-05,Inconsistent export pattern,RECOMMENDATION,Mix of named and default exports in same module,Export analysis,PARTIAL
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
rule_id,rule_idea,implementation_hint,false_positive_risk,scope,example_pattern
|
|
2
|
+
HG-API-01,Detect deep index.ts files,Count path depth of index.ts files,LOW,index.ts files,src/a/b/c/index.ts (depth > 2)
|
|
3
|
+
HG-API-02,Require JSDoc for public exports,Check exported symbols for JSDoc comments,MEDIUM,Public API files,export function foo() without /** */
|
|
4
|
+
HG-API-03,Detect default export outside pages/,Check for default exports in non-framework files,LOW,Non-page TypeScript files,export default in non-page files
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# API Design Recipes
|
|
2
|
+
|
|
3
|
+
## Recipe: Remove Deep Index Files
|
|
4
|
+
|
|
5
|
+
**Problem**: Multiple nested index.ts files causing coupling
|
|
6
|
+
|
|
7
|
+
**Steps**:
|
|
8
|
+
1. Identify all index.ts files >2 levels deep
|
|
9
|
+
2. Move exports to root index.ts or package.json exports
|
|
10
|
+
3. Remove intermediate index.ts files
|
|
11
|
+
4. Update imports to use direct paths or root exports
|
|
12
|
+
|
|
13
|
+
## Recipe: Convert Default to Named Exports
|
|
14
|
+
|
|
15
|
+
**Problem**: Overuse of default exports
|
|
16
|
+
|
|
17
|
+
**Steps**:
|
|
18
|
+
1. Change `export default` to `export const/function`
|
|
19
|
+
2. Update all import statements
|
|
20
|
+
3. Verify no framework requirements for default export
|
|
21
|
+
|
|
22
|
+
## Recipe: Document Public API
|
|
23
|
+
|
|
24
|
+
**Problem**: Public exports lack documentation
|
|
25
|
+
|
|
26
|
+
**Steps**:
|
|
27
|
+
1. Add JSDoc/TSDoc comments to all public exports
|
|
28
|
+
2. Include @param, @returns, @throws
|
|
29
|
+
3. Add usage examples for complex APIs
|
|
30
|
+
4. Document breaking changes and deprecations
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
id,title,severity,description,evidence_requirements,automatable
|
|
2
|
+
C-ASYNC-01,Unhandled promise rejection,RECOMMENDATION,Promise without catch or await,Code analysis,YES
|
|
3
|
+
C-ASYNC-02,Race condition risk,RECOMMENDATION,Concurrent state mutations,Code flow analysis,NO
|
|
4
|
+
C-ASYNC-03,Missing async/await,RECOMMENDATION,Promise chains instead of async/await,Code pattern,PARTIAL
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Complexity Anti-Patterns
|
|
2
|
+
|
|
3
|
+
## Anti-Pattern: Arrow Code
|
|
4
|
+
|
|
5
|
+
**Description**: Deeply nested if statements forming arrow shape
|
|
6
|
+
|
|
7
|
+
**Detection Signals**:
|
|
8
|
+
- Indentation >4 levels
|
|
9
|
+
- Multiple nested if/for/while
|
|
10
|
+
- Hard to follow control flow
|
|
11
|
+
|
|
12
|
+
**Why It's Bad**:
|
|
13
|
+
- Hard to read and understand
|
|
14
|
+
- Difficult to test all paths
|
|
15
|
+
- Error-prone to modify
|
|
16
|
+
|
|
17
|
+
**Fix**:
|
|
18
|
+
- Use early returns
|
|
19
|
+
- Extract nested logic to functions
|
|
20
|
+
- Flatten structure
|
|
21
|
+
|
|
22
|
+
## Anti-Pattern: God Function
|
|
23
|
+
|
|
24
|
+
**Description**: Single function doing everything
|
|
25
|
+
|
|
26
|
+
**Detection Signals**:
|
|
27
|
+
- Function >100 lines
|
|
28
|
+
- Multiple responsibilities
|
|
29
|
+
- High cyclomatic complexity
|
|
30
|
+
|
|
31
|
+
**Why It's Bad**:
|
|
32
|
+
- Hard to understand
|
|
33
|
+
- Difficult to test
|
|
34
|
+
- Violates single responsibility
|
|
35
|
+
|
|
36
|
+
**Fix**:
|
|
37
|
+
- Extract smaller functions
|
|
38
|
+
- Each function does one thing
|
|
39
|
+
- Use descriptive names
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
id,title,severity,description,evidence_requirements,automatable
|
|
2
|
+
C-COMPLEX-01,Excessive nesting depth,RECOMMENDATION,Code has >4 levels of nesting,Indentation analysis,YES
|
|
3
|
+
C-COMPLEX-02,Long function,RECOMMENDATION,Function exceeds 60 lines,Line count,YES
|
|
4
|
+
C-COMPLEX-03,God function,RECOMMENDATION,Function has too many responsibilities,Complexity metrics,PARTIAL
|
|
5
|
+
C-COMPLEX-04,High cyclomatic complexity,RECOMMENDATION,Function has >15 decision points,Complexity analysis,YES
|
|
6
|
+
C-COMPLEX-05,Poor variable naming,RECOMMENDATION,Variables named a/b/x/temp without context,Identifier analysis,PARTIAL
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
rule_id,rule_idea,implementation_hint,false_positive_risk,scope,example_pattern
|
|
2
|
+
HG-COMPLEX-01,Limit function length to 60 lines,Count lines between function declaration and closing brace,LOW,All functions,Functions with >60 lines
|
|
3
|
+
HG-COMPLEX-02,Limit cyclomatic complexity to 15,Calculate decision points in function,LOW,All functions,Functions with >15 if/for/while/case
|
|
4
|
+
HG-COMPLEX-03,Limit nesting depth to 4,Track indentation levels,LOW,All code,Code with >4 levels of nesting
|
|
5
|
+
HG-COMPLEX-04,Flag single-letter variables,Check variable names against pattern,HIGH,All variables,Variables named a/b/c/x/y/z without context
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Complexity Reduction Recipes
|
|
2
|
+
|
|
3
|
+
## Recipe: Reduce Nesting with Early Returns
|
|
4
|
+
|
|
5
|
+
**Problem**: Deep nesting makes code hard to read
|
|
6
|
+
|
|
7
|
+
**Steps**:
|
|
8
|
+
1. Identify nested if statements
|
|
9
|
+
2. Invert conditions and return early
|
|
10
|
+
3. Flatten the code structure
|
|
11
|
+
|
|
12
|
+
**Example**:
|
|
13
|
+
```typescript
|
|
14
|
+
// Before
|
|
15
|
+
function process(data: Data) {
|
|
16
|
+
if (data) {
|
|
17
|
+
if (data.isValid) {
|
|
18
|
+
if (data.hasPermission) {
|
|
19
|
+
return doWork(data)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// After
|
|
27
|
+
function process(data: Data) {
|
|
28
|
+
if (!data) return null
|
|
29
|
+
if (!data.isValid) return null
|
|
30
|
+
if (!data.hasPermission) return null
|
|
31
|
+
return doWork(data)
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Recipe: Extract Method
|
|
36
|
+
|
|
37
|
+
**Problem**: Long function doing too much
|
|
38
|
+
|
|
39
|
+
**Steps**:
|
|
40
|
+
1. Identify logical sections
|
|
41
|
+
2. Extract each section to named function
|
|
42
|
+
3. Keep functions focused and small
|
|
43
|
+
|
|
44
|
+
## Recipe: Replace Complex Condition with Function
|
|
45
|
+
|
|
46
|
+
**Problem**: Complex boolean expressions
|
|
47
|
+
|
|
48
|
+
**Steps**:
|
|
49
|
+
1. Extract condition to named function
|
|
50
|
+
2. Use descriptive name explaining intent
|
|
51
|
+
3. Improve readability
|
|
52
|
+
|
|
53
|
+
**Example**:
|
|
54
|
+
```typescript
|
|
55
|
+
// Before
|
|
56
|
+
if (user.age >= 18 && user.hasLicense && !user.isSuspended) {
|
|
57
|
+
allowDriving()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// After
|
|
61
|
+
function canDrive(user: User) {
|
|
62
|
+
return user.age >= 18 && user.hasLicense && !user.isSuspended
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (canDrive(user)) {
|
|
66
|
+
allowDriving()
|
|
67
|
+
}
|
|
68
|
+
```
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Dependency Anti-Patterns
|
|
2
|
+
|
|
3
|
+
## Anti-Pattern: Dependency Hell
|
|
4
|
+
|
|
5
|
+
**Description**: Complex web of circular and tangled dependencies
|
|
6
|
+
|
|
7
|
+
**Detection Signals**:
|
|
8
|
+
- Multiple circular dependency warnings
|
|
9
|
+
- Changes in one module break many others
|
|
10
|
+
- Dependency graph looks like spaghetti
|
|
11
|
+
|
|
12
|
+
**Why It's Bad**:
|
|
13
|
+
- Hard to understand code flow
|
|
14
|
+
- Difficult to test in isolation
|
|
15
|
+
- Refactoring becomes risky
|
|
16
|
+
|
|
17
|
+
**Fix**:
|
|
18
|
+
- Map dependency graph
|
|
19
|
+
- Break cycles systematically
|
|
20
|
+
- Establish clear dependency direction
|
|
21
|
+
|
|
22
|
+
## Anti-Pattern: God Object Dependency
|
|
23
|
+
|
|
24
|
+
**Description**: One module that everything depends on
|
|
25
|
+
|
|
26
|
+
**Detection Signals**:
|
|
27
|
+
- Single module imported by >80% of codebase
|
|
28
|
+
- Module has too many responsibilities
|
|
29
|
+
- Changes to module require extensive testing
|
|
30
|
+
|
|
31
|
+
**Why It's Bad**:
|
|
32
|
+
- Single point of failure
|
|
33
|
+
- Bottleneck for development
|
|
34
|
+
- Hard to maintain and evolve
|
|
35
|
+
|
|
36
|
+
**Fix**:
|
|
37
|
+
- Split into focused modules
|
|
38
|
+
- Use dependency inversion
|
|
39
|
+
- Create clear interfaces
|
|
40
|
+
|
|
41
|
+
## Anti-Pattern: Shotgun Surgery
|
|
42
|
+
|
|
43
|
+
**Description**: Single change requires modifications in many modules
|
|
44
|
+
|
|
45
|
+
**Detection Signals**:
|
|
46
|
+
- Feature changes touch >10 files
|
|
47
|
+
- Related logic scattered across codebase
|
|
48
|
+
- High coupling between modules
|
|
49
|
+
|
|
50
|
+
**Why It's Bad**:
|
|
51
|
+
- Increases risk of bugs
|
|
52
|
+
- Slows down development
|
|
53
|
+
- Hard to ensure consistency
|
|
54
|
+
|
|
55
|
+
**Fix**:
|
|
56
|
+
- Colocate related functionality
|
|
57
|
+
- Reduce coupling
|
|
58
|
+
- Use events/observers for cross-cutting concerns
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
id,title,severity,description,evidence_requirements,automatable
|
|
2
|
+
C-DEP-01,Circular dependency detected,BLOCKER,Circular import chain between modules,Dependency graph with cycle,YES
|
|
3
|
+
C-DEP-02,High coupling between modules,RECOMMENDATION,Module imports too many other modules,Import count analysis,PARTIAL
|
|
4
|
+
C-DEP-03,Upward dependency violation,BLOCKER,Lower layer depends on higher layer,Dependency trace + layer info,PARTIAL
|
|
5
|
+
C-DEP-04,Tight coupling to external library,RECOMMENDATION,Direct usage of external library throughout codebase,Import analysis,NO
|
|
6
|
+
C-DEP-05,Missing dependency abstraction,RECOMMENDATION,Concrete dependency instead of interface,Type analysis,NO
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
rule_id,rule_idea,implementation_hint,false_positive_risk,scope,example_pattern
|
|
2
|
+
HG-DEP-01,Detect circular imports,Build import graph with DFS cycle detection,LOW,All TypeScript/JavaScript files,Import cycles in dependency graph
|
|
3
|
+
HG-DEP-02,Limit module fan-out,Count imports per file and flag >15,MEDIUM,All source files,File with >15 import statements
|
|
4
|
+
HG-DEP-03,Detect upward layer dependencies,Combine import analysis with layer classification,LOW,TypeScript files,Lower layer importing from higher layer
|
|
5
|
+
HG-DEP-04,Flag direct external library usage in domain,Check domain/* files for external package imports,MEDIUM,domain/* files,"import axios/fetch/prisma in domain/*"
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Dependency Violation Recipes
|
|
2
|
+
|
|
3
|
+
## Recipe: Break Circular Dependency
|
|
4
|
+
|
|
5
|
+
**Problem**: Module A imports B, B imports A
|
|
6
|
+
|
|
7
|
+
**Steps**:
|
|
8
|
+
1. Identify the shared concern causing the cycle
|
|
9
|
+
2. Extract shared types/interfaces to separate module
|
|
10
|
+
3. Both A and B import from the new module
|
|
11
|
+
4. Verify cycle is broken
|
|
12
|
+
|
|
13
|
+
**Example**:
|
|
14
|
+
```typescript
|
|
15
|
+
// Before: Cycle between user.ts and order.ts
|
|
16
|
+
// user.ts
|
|
17
|
+
import { Order } from './order'
|
|
18
|
+
export interface User { orders: Order[] }
|
|
19
|
+
|
|
20
|
+
// order.ts
|
|
21
|
+
import { User } from './user'
|
|
22
|
+
export interface Order { user: User }
|
|
23
|
+
|
|
24
|
+
// After: Extract to types
|
|
25
|
+
// types.ts
|
|
26
|
+
export interface UserRef { id: string; name: string }
|
|
27
|
+
export interface OrderRef { id: string; total: number }
|
|
28
|
+
|
|
29
|
+
// user.ts
|
|
30
|
+
import { OrderRef } from './types'
|
|
31
|
+
export interface User { orders: OrderRef[] }
|
|
32
|
+
|
|
33
|
+
// order.ts
|
|
34
|
+
import { UserRef } from './types'
|
|
35
|
+
export interface Order { user: UserRef }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Recipe: Reduce Module Coupling
|
|
39
|
+
|
|
40
|
+
**Problem**: Module imports from too many other modules
|
|
41
|
+
|
|
42
|
+
**Steps**:
|
|
43
|
+
1. Identify common dependencies
|
|
44
|
+
2. Group related functionality
|
|
45
|
+
3. Create facade or aggregate module
|
|
46
|
+
4. Reduce direct dependencies
|
|
47
|
+
|
|
48
|
+
## Recipe: Abstract External Dependency
|
|
49
|
+
|
|
50
|
+
**Problem**: External library used directly throughout code
|
|
51
|
+
|
|
52
|
+
**Steps**:
|
|
53
|
+
1. Create adapter interface in domain
|
|
54
|
+
2. Implement adapter in infrastructure
|
|
55
|
+
3. Inject adapter through dependency injection
|
|
56
|
+
4. Replace direct library usage with adapter
|
|
57
|
+
|
|
58
|
+
**Example**:
|
|
59
|
+
```typescript
|
|
60
|
+
// Before: Direct axios usage in domain
|
|
61
|
+
// domain/user/service.ts
|
|
62
|
+
import axios from 'axios'
|
|
63
|
+
export async function getUser(id: string) {
|
|
64
|
+
return axios.get(`/api/users/${id}`)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// After: Abstract with adapter
|
|
68
|
+
// domain/user/repository.ts
|
|
69
|
+
export interface UserRepository {
|
|
70
|
+
getUser(id: string): Promise<User>
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// infra/api/userApiRepository.ts
|
|
74
|
+
import axios from 'axios'
|
|
75
|
+
export class UserApiRepository implements UserRepository {
|
|
76
|
+
async getUser(id: string) {
|
|
77
|
+
const response = await axios.get(`/api/users/${id}`)
|
|
78
|
+
return mapToUser(response.data)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// domain/user/service.ts
|
|
83
|
+
export class UserService {
|
|
84
|
+
constructor(private repo: UserRepository) {}
|
|
85
|
+
async getUser(id: string) {
|
|
86
|
+
return this.repo.getUser(id)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
id,title,severity,description,evidence_requirements,automatable
|
|
2
|
+
C-DOC-01,Missing JSDoc for public API,RECOMMENDATION,Public function lacks documentation,Export + comment analysis,YES
|
|
3
|
+
C-DOC-02,Outdated comments,RECOMMENDATION,Comments contradict code,Code analysis,NO
|
|
4
|
+
C-DOC-03,Complex logic without explanation,RECOMMENDATION,Complex code lacks why comment,Complexity + comment analysis,NO
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
id,title,severity,description,evidence_requirements,automatable
|
|
2
|
+
C-ERROR-01,Empty catch block,RECOMMENDATION,Error caught but not handled,Code pattern,YES
|
|
3
|
+
C-ERROR-02,Generic error thrown,RECOMMENDATION,Throwing generic Error instead of custom type,Error analysis,PARTIAL
|
|
4
|
+
C-ERROR-03,Missing error boundary,RECOMMENDATION,No error handling for critical path,Code flow analysis,NO
|