claude-code-workflow 6.3.22 → 6.3.24
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/.claude/agents/issue-plan-agent.md +10 -5
- package/.claude/commands/issue/plan.md +1 -1
- package/.claude/skills/review-code/SKILL.md +170 -0
- package/.claude/skills/review-code/phases/actions/action-collect-context.md +139 -0
- package/.claude/skills/review-code/phases/actions/action-complete.md +115 -0
- package/.claude/skills/review-code/phases/actions/action-deep-review.md +302 -0
- package/.claude/skills/review-code/phases/actions/action-generate-report.md +263 -0
- package/.claude/skills/review-code/phases/actions/action-quick-scan.md +164 -0
- package/.claude/skills/review-code/phases/orchestrator.md +251 -0
- package/.claude/skills/review-code/phases/state-manager.md +752 -0
- package/.claude/skills/review-code/phases/state-schema.md +174 -0
- package/.claude/skills/review-code/specs/issue-classification.md +228 -0
- package/.claude/skills/review-code/specs/quality-standards.md +214 -0
- package/.claude/skills/review-code/specs/review-dimensions.md +337 -0
- package/.claude/skills/review-code/specs/rules/architecture-rules.json +63 -0
- package/.claude/skills/review-code/specs/rules/correctness-rules.json +60 -0
- package/.claude/skills/review-code/specs/rules/index.md +140 -0
- package/.claude/skills/review-code/specs/rules/performance-rules.json +59 -0
- package/.claude/skills/review-code/specs/rules/readability-rules.json +60 -0
- package/.claude/skills/review-code/specs/rules/security-rules.json +58 -0
- package/.claude/skills/review-code/specs/rules/testing-rules.json +59 -0
- package/.claude/skills/review-code/templates/issue-template.md +186 -0
- package/.claude/skills/review-code/templates/review-report.md +173 -0
- package/.claude/skills/skill-generator/SKILL.md +56 -17
- package/.claude/skills/skill-generator/templates/autonomous-orchestrator.md +10 -0
- package/.claude/skills/skill-generator/templates/sequential-phase.md +9 -0
- package/.claude/skills/skill-generator/templates/skill-md.md +84 -5
- package/.claude/workflows/cli-templates/schemas/solution-schema.json +3 -3
- package/ccw/src/templates/dashboard-js/views/issue-manager.js +8 -0
- package/package.json +1 -1
- package/.claude/skills/code-reviewer/README.md +0 -340
- package/.claude/skills/code-reviewer/SKILL.md +0 -308
- package/.claude/skills/code-reviewer/phases/01-code-discovery.md +0 -246
- package/.claude/skills/code-reviewer/phases/02-security-analysis.md +0 -442
- package/.claude/skills/code-reviewer/phases/03-best-practices-review.md +0 -36
- package/.claude/skills/code-reviewer/phases/04-report-generation.md +0 -278
- package/.claude/skills/code-reviewer/specs/best-practices-requirements.md +0 -346
- package/.claude/skills/code-reviewer/specs/quality-standards.md +0 -252
- package/.claude/skills/code-reviewer/specs/security-requirements.md +0 -243
- package/.claude/skills/code-reviewer/templates/best-practice-finding.md +0 -234
- package/.claude/skills/code-reviewer/templates/report-template.md +0 -316
- package/.claude/skills/code-reviewer/templates/security-finding.md +0 -161
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
# Phase 4: Report Generation
|
|
2
|
-
|
|
3
|
-
## Objective
|
|
4
|
-
|
|
5
|
-
Consolidate security and best practices findings into a comprehensive, actionable code review report.
|
|
6
|
-
|
|
7
|
-
## Input
|
|
8
|
-
|
|
9
|
-
- **Security Findings**: `.code-review/security-findings.json`
|
|
10
|
-
- **Best Practices Findings**: `.code-review/best-practices-findings.json`
|
|
11
|
-
- **File Inventory**: `.code-review/inventory.json`
|
|
12
|
-
|
|
13
|
-
## Process
|
|
14
|
-
|
|
15
|
-
### Step 1: Load All Findings
|
|
16
|
-
|
|
17
|
-
```javascript
|
|
18
|
-
const securityFindings = JSON.parse(
|
|
19
|
-
await Read({ file_path: '.code-review/security-findings.json' })
|
|
20
|
-
);
|
|
21
|
-
const bestPracticesFindings = JSON.parse(
|
|
22
|
-
await Read({ file_path: '.code-review/best-practices-findings.json' })
|
|
23
|
-
);
|
|
24
|
-
const inventory = JSON.parse(
|
|
25
|
-
await Read({ file_path: '.code-review/inventory.json' })
|
|
26
|
-
);
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Step 2: Aggregate Statistics
|
|
30
|
-
|
|
31
|
-
```javascript
|
|
32
|
-
const stats = {
|
|
33
|
-
total_files_reviewed: inventory.total_files,
|
|
34
|
-
total_findings: securityFindings.total_findings + bestPracticesFindings.total_findings,
|
|
35
|
-
by_severity: {
|
|
36
|
-
critical: securityFindings.by_severity.critical,
|
|
37
|
-
high: securityFindings.by_severity.high + bestPracticesFindings.by_severity.high,
|
|
38
|
-
medium: securityFindings.by_severity.medium + bestPracticesFindings.by_severity.medium,
|
|
39
|
-
low: securityFindings.by_severity.low + bestPracticesFindings.by_severity.low,
|
|
40
|
-
},
|
|
41
|
-
by_category: {
|
|
42
|
-
security: securityFindings.total_findings,
|
|
43
|
-
code_quality: bestPracticesFindings.by_category.code_quality,
|
|
44
|
-
performance: bestPracticesFindings.by_category.performance,
|
|
45
|
-
maintainability: bestPracticesFindings.by_category.maintainability,
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### Step 3: Generate Comprehensive Report
|
|
51
|
-
|
|
52
|
-
```markdown
|
|
53
|
-
# Comprehensive Code Review Report
|
|
54
|
-
|
|
55
|
-
**Generated**: {timestamp}
|
|
56
|
-
**Scope**: {scope}
|
|
57
|
-
**Files Reviewed**: {total_files}
|
|
58
|
-
**Total Findings**: {total_findings}
|
|
59
|
-
|
|
60
|
-
## Executive Summary
|
|
61
|
-
|
|
62
|
-
{Provide high-level overview of code health}
|
|
63
|
-
|
|
64
|
-
### Risk Assessment
|
|
65
|
-
|
|
66
|
-
{Calculate risk score based on findings}
|
|
67
|
-
|
|
68
|
-
### Compliance Status
|
|
69
|
-
|
|
70
|
-
{Map findings to compliance requirements}
|
|
71
|
-
|
|
72
|
-
## Detailed Findings
|
|
73
|
-
|
|
74
|
-
{Merge and organize security + best practices findings}
|
|
75
|
-
|
|
76
|
-
## Action Plan
|
|
77
|
-
|
|
78
|
-
{Prioritized list of fixes with effort estimates}
|
|
79
|
-
|
|
80
|
-
## Appendix
|
|
81
|
-
|
|
82
|
-
{Technical details, references, configuration}
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### Step 4: Generate Fix Tracking Checklist
|
|
86
|
-
|
|
87
|
-
Create actionable checklist for developers:
|
|
88
|
-
|
|
89
|
-
```markdown
|
|
90
|
-
# Code Review Fix Checklist
|
|
91
|
-
|
|
92
|
-
## Critical Issues (Fix Immediately)
|
|
93
|
-
|
|
94
|
-
- [ ] [SEC-001] SQL Injection in src/auth/user-service.ts:145
|
|
95
|
-
- [ ] [SEC-002] Hardcoded JWT Secret in src/auth/jwt.ts:23
|
|
96
|
-
- [ ] [SEC-003] XSS Vulnerability in src/api/comments.ts:89
|
|
97
|
-
|
|
98
|
-
## High Priority Issues (Fix This Week)
|
|
99
|
-
|
|
100
|
-
- [ ] [SEC-004] Missing Authorization Check in src/api/admin.ts:34
|
|
101
|
-
- [ ] [BP-001] N+1 Query Pattern in src/api/orders.ts:45
|
|
102
|
-
...
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Step 5: Generate Metrics Dashboard
|
|
106
|
-
|
|
107
|
-
```markdown
|
|
108
|
-
## Code Health Metrics
|
|
109
|
-
|
|
110
|
-
### Security Score: 68/100
|
|
111
|
-
- Critical Issues: 3 (-30 points)
|
|
112
|
-
- High Issues: 8 (-2 points each)
|
|
113
|
-
|
|
114
|
-
### Code Quality Score: 75/100
|
|
115
|
-
- High Complexity Functions: 2
|
|
116
|
-
- Code Duplication: 5%
|
|
117
|
-
- Dead Code: 3 instances
|
|
118
|
-
|
|
119
|
-
### Performance Score: 82/100
|
|
120
|
-
- N+1 Queries: 3
|
|
121
|
-
- Inefficient Algorithms: 2
|
|
122
|
-
|
|
123
|
-
### Maintainability Score: 70/100
|
|
124
|
-
- Documentation Coverage: 65%
|
|
125
|
-
- Test Coverage: 72%
|
|
126
|
-
- Missing Tests: 5 files
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
## Output
|
|
130
|
-
|
|
131
|
-
### Main Report
|
|
132
|
-
|
|
133
|
-
Save to `.code-review/REPORT.md`:
|
|
134
|
-
|
|
135
|
-
- Executive summary
|
|
136
|
-
- Detailed findings (security + best practices)
|
|
137
|
-
- Action plan with priorities
|
|
138
|
-
- Metrics and scores
|
|
139
|
-
- References and compliance mapping
|
|
140
|
-
|
|
141
|
-
### Fix Checklist
|
|
142
|
-
|
|
143
|
-
Save to `.code-review/FIX-CHECKLIST.md`:
|
|
144
|
-
|
|
145
|
-
- Organized by severity
|
|
146
|
-
- Checkboxes for tracking
|
|
147
|
-
- File:line references
|
|
148
|
-
- Effort estimates
|
|
149
|
-
|
|
150
|
-
### JSON Summary
|
|
151
|
-
|
|
152
|
-
Save to `.code-review/summary.json`:
|
|
153
|
-
|
|
154
|
-
```json
|
|
155
|
-
{
|
|
156
|
-
"report_date": "2024-01-15T12:00:00Z",
|
|
157
|
-
"scope": "src/**/*",
|
|
158
|
-
"statistics": {
|
|
159
|
-
"total_files": 247,
|
|
160
|
-
"total_findings": 69,
|
|
161
|
-
"by_severity": { "critical": 3, "high": 13, "medium": 30, "low": 23 },
|
|
162
|
-
"by_category": {
|
|
163
|
-
"security": 24,
|
|
164
|
-
"code_quality": 18,
|
|
165
|
-
"performance": 12,
|
|
166
|
-
"maintainability": 15
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
"scores": {
|
|
170
|
-
"security": 68,
|
|
171
|
-
"code_quality": 75,
|
|
172
|
-
"performance": 82,
|
|
173
|
-
"maintainability": 70,
|
|
174
|
-
"overall": 74
|
|
175
|
-
},
|
|
176
|
-
"risk_level": "MEDIUM",
|
|
177
|
-
"action_required": true
|
|
178
|
-
}
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
## Report Template
|
|
182
|
-
|
|
183
|
-
Full report includes:
|
|
184
|
-
|
|
185
|
-
1. **Executive Summary**
|
|
186
|
-
- Overall code health
|
|
187
|
-
- Risk assessment
|
|
188
|
-
- Key recommendations
|
|
189
|
-
|
|
190
|
-
2. **Security Findings** (from Phase 2)
|
|
191
|
-
- Critical/High/Medium/Low
|
|
192
|
-
- OWASP/CWE mappings
|
|
193
|
-
- Fix recommendations with code examples
|
|
194
|
-
|
|
195
|
-
3. **Best Practices Findings** (from Phase 3)
|
|
196
|
-
- Code quality issues
|
|
197
|
-
- Performance concerns
|
|
198
|
-
- Maintainability gaps
|
|
199
|
-
|
|
200
|
-
4. **Metrics Dashboard**
|
|
201
|
-
- Security score
|
|
202
|
-
- Code quality score
|
|
203
|
-
- Performance score
|
|
204
|
-
- Maintainability score
|
|
205
|
-
|
|
206
|
-
5. **Action Plan**
|
|
207
|
-
- Immediate actions (critical)
|
|
208
|
-
- Short-term (1 week)
|
|
209
|
-
- Medium-term (1 month)
|
|
210
|
-
- Long-term (3 months)
|
|
211
|
-
|
|
212
|
-
6. **Compliance Impact**
|
|
213
|
-
- PCI DSS findings
|
|
214
|
-
- HIPAA findings
|
|
215
|
-
- GDPR findings
|
|
216
|
-
- SOC 2 findings
|
|
217
|
-
|
|
218
|
-
7. **Appendix**
|
|
219
|
-
- Full findings list
|
|
220
|
-
- Configuration used
|
|
221
|
-
- Tools and versions
|
|
222
|
-
- References
|
|
223
|
-
|
|
224
|
-
## State Management
|
|
225
|
-
|
|
226
|
-
```json
|
|
227
|
-
{
|
|
228
|
-
"phase": "04-report-generation",
|
|
229
|
-
"status": "completed",
|
|
230
|
-
"timestamp": "2024-01-15T12:00:00Z",
|
|
231
|
-
"input": {
|
|
232
|
-
"security_findings": ".code-review/security-findings.json",
|
|
233
|
-
"best_practices_findings": ".code-review/best-practices-findings.json"
|
|
234
|
-
},
|
|
235
|
-
"output": {
|
|
236
|
-
"report": ".code-review/REPORT.md",
|
|
237
|
-
"checklist": ".code-review/FIX-CHECKLIST.md",
|
|
238
|
-
"summary": ".code-review/summary.json"
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
## Agent Instructions
|
|
244
|
-
|
|
245
|
-
```markdown
|
|
246
|
-
You are in Phase 4 (FINAL) of the Code Review workflow. Generate comprehensive report.
|
|
247
|
-
|
|
248
|
-
**Instructions**:
|
|
249
|
-
1. Load security findings from Phase 2
|
|
250
|
-
2. Load best practices findings from Phase 3
|
|
251
|
-
3. Aggregate statistics and calculate scores
|
|
252
|
-
4. Generate comprehensive markdown report
|
|
253
|
-
5. Create fix tracking checklist
|
|
254
|
-
6. Generate JSON summary
|
|
255
|
-
7. Inform user of completion and output locations
|
|
256
|
-
|
|
257
|
-
**Tools Available**:
|
|
258
|
-
- Read (load findings)
|
|
259
|
-
- Write (save reports)
|
|
260
|
-
|
|
261
|
-
**Output Requirements**:
|
|
262
|
-
- REPORT.md (comprehensive markdown report)
|
|
263
|
-
- FIX-CHECKLIST.md (actionable checklist)
|
|
264
|
-
- summary.json (machine-readable summary)
|
|
265
|
-
- All files in .code-review/ directory
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
## Validation
|
|
269
|
-
|
|
270
|
-
- ✅ All findings consolidated
|
|
271
|
-
- ✅ Scores calculated
|
|
272
|
-
- ✅ Action plan generated
|
|
273
|
-
- ✅ Reports saved to .code-review/
|
|
274
|
-
- ✅ User notified of completion
|
|
275
|
-
|
|
276
|
-
## Completion
|
|
277
|
-
|
|
278
|
-
Code review complete! Outputs available in `.code-review/` directory.
|
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
# Best Practices Requirements Specification
|
|
2
|
-
|
|
3
|
-
## Code Quality Standards
|
|
4
|
-
|
|
5
|
-
### Naming Conventions
|
|
6
|
-
|
|
7
|
-
**TypeScript/JavaScript**:
|
|
8
|
-
- Classes/Interfaces: PascalCase (`UserService`, `IUserRepository`)
|
|
9
|
-
- Functions/Methods: camelCase (`getUserById`, `validateEmail`)
|
|
10
|
-
- Constants: UPPER_SNAKE_CASE (`MAX_RETRY_COUNT`, `API_BASE_URL`)
|
|
11
|
-
- Private properties: prefix with `_` or `#` (`_cache`, `#secretKey`)
|
|
12
|
-
|
|
13
|
-
**Python**:
|
|
14
|
-
- Classes: PascalCase (`UserService`, `DatabaseConnection`)
|
|
15
|
-
- Functions: snake_case (`get_user_by_id`, `validate_email`)
|
|
16
|
-
- Constants: UPPER_SNAKE_CASE (`MAX_RETRY_COUNT`)
|
|
17
|
-
- Private: prefix with `_` (`_internal_cache`)
|
|
18
|
-
|
|
19
|
-
**Java**:
|
|
20
|
-
- Classes/Interfaces: PascalCase (`UserService`, `IUserRepository`)
|
|
21
|
-
- Methods: camelCase (`getUserById`, `validateEmail`)
|
|
22
|
-
- Constants: UPPER_SNAKE_CASE (`MAX_RETRY_COUNT`)
|
|
23
|
-
- Packages: lowercase (`com.example.service`)
|
|
24
|
-
|
|
25
|
-
### Function Complexity
|
|
26
|
-
|
|
27
|
-
**Cyclomatic Complexity Thresholds**:
|
|
28
|
-
- **Low**: 1-5 (simple functions, easy to test)
|
|
29
|
-
- **Medium**: 6-10 (acceptable, well-structured)
|
|
30
|
-
- **High**: 11-20 (needs refactoring)
|
|
31
|
-
- **Very High**: 21+ (critical, must refactor)
|
|
32
|
-
|
|
33
|
-
**Calculation**:
|
|
34
|
-
```
|
|
35
|
-
Complexity = 1 (base)
|
|
36
|
-
+ count(if)
|
|
37
|
-
+ count(else if)
|
|
38
|
-
+ count(while)
|
|
39
|
-
+ count(for)
|
|
40
|
-
+ count(case)
|
|
41
|
-
+ count(catch)
|
|
42
|
-
+ count(&&)
|
|
43
|
-
+ count(||)
|
|
44
|
-
+ count(? :)
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Code Duplication
|
|
48
|
-
|
|
49
|
-
**Thresholds**:
|
|
50
|
-
- **Acceptable**: < 3% duplication
|
|
51
|
-
- **Warning**: 3-5% duplication
|
|
52
|
-
- **Critical**: > 5% duplication
|
|
53
|
-
|
|
54
|
-
**Detection**:
|
|
55
|
-
- Minimum block size: 5 lines
|
|
56
|
-
- Similarity threshold: 85%
|
|
57
|
-
- Ignore: Comments, imports, trivial getters/setters
|
|
58
|
-
|
|
59
|
-
### Dead Code Detection
|
|
60
|
-
|
|
61
|
-
**Targets**:
|
|
62
|
-
- Unused imports
|
|
63
|
-
- Unused variables/functions (not exported)
|
|
64
|
-
- Unreachable code (after return/throw)
|
|
65
|
-
- Commented-out code blocks (> 5 lines)
|
|
66
|
-
|
|
67
|
-
## Performance Standards
|
|
68
|
-
|
|
69
|
-
### N+1 Query Prevention
|
|
70
|
-
|
|
71
|
-
**Anti-patterns**:
|
|
72
|
-
```javascript
|
|
73
|
-
// ❌ N+1 Query
|
|
74
|
-
for (const order of orders) {
|
|
75
|
-
const user = await User.findById(order.userId);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// ✅ Batch Query
|
|
79
|
-
const userIds = orders.map(o => o.userId);
|
|
80
|
-
const users = await User.findByIds(userIds);
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Algorithm Efficiency
|
|
84
|
-
|
|
85
|
-
**Common Issues**:
|
|
86
|
-
- Nested loops (O(n²)) when O(n) possible
|
|
87
|
-
- Array.indexOf in loop → use Set.has()
|
|
88
|
-
- Array.filter().length → use Array.some()
|
|
89
|
-
- Multiple array iterations → combine into one pass
|
|
90
|
-
|
|
91
|
-
**Acceptable Complexity**:
|
|
92
|
-
- **O(1)**: Ideal for lookups
|
|
93
|
-
- **O(log n)**: Good for search
|
|
94
|
-
- **O(n)**: Acceptable for linear scan
|
|
95
|
-
- **O(n log n)**: Acceptable for sorting
|
|
96
|
-
- **O(n²)**: Avoid if possible, document if necessary
|
|
97
|
-
|
|
98
|
-
### Memory Leak Prevention
|
|
99
|
-
|
|
100
|
-
**Common Issues**:
|
|
101
|
-
- Event listeners without cleanup
|
|
102
|
-
- setInterval without clearInterval
|
|
103
|
-
- Global variable accumulation
|
|
104
|
-
- Circular references
|
|
105
|
-
- Large array/object allocations
|
|
106
|
-
|
|
107
|
-
**Patterns**:
|
|
108
|
-
```javascript
|
|
109
|
-
// ❌ Memory Leak
|
|
110
|
-
element.addEventListener('click', handler);
|
|
111
|
-
// No cleanup
|
|
112
|
-
|
|
113
|
-
// ✅ Proper Cleanup
|
|
114
|
-
useEffect(() => {
|
|
115
|
-
element.addEventListener('click', handler);
|
|
116
|
-
return () => element.removeEventListener('click', handler);
|
|
117
|
-
}, []);
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### Resource Cleanup
|
|
121
|
-
|
|
122
|
-
**Required Cleanup**:
|
|
123
|
-
- Database connections
|
|
124
|
-
- File handles
|
|
125
|
-
- Network sockets
|
|
126
|
-
- Timers (setTimeout, setInterval)
|
|
127
|
-
- Event listeners
|
|
128
|
-
|
|
129
|
-
## Maintainability Standards
|
|
130
|
-
|
|
131
|
-
### Documentation Requirements
|
|
132
|
-
|
|
133
|
-
**Required for**:
|
|
134
|
-
- All exported functions/classes
|
|
135
|
-
- Public APIs
|
|
136
|
-
- Complex algorithms
|
|
137
|
-
- Non-obvious business logic
|
|
138
|
-
|
|
139
|
-
**JSDoc Format**:
|
|
140
|
-
```javascript
|
|
141
|
-
/**
|
|
142
|
-
* Validates user credentials and generates JWT token
|
|
143
|
-
*
|
|
144
|
-
* @param {string} username - User's username or email
|
|
145
|
-
* @param {string} password - Plain text password
|
|
146
|
-
* @returns {Promise<{token: string, expiresAt: Date}>} JWT token and expiration
|
|
147
|
-
* @throws {AuthenticationError} If credentials are invalid
|
|
148
|
-
*
|
|
149
|
-
* @example
|
|
150
|
-
* const {token} = await authenticateUser('john@example.com', 'secret123');
|
|
151
|
-
*/
|
|
152
|
-
async function authenticateUser(username, password) {
|
|
153
|
-
// ...
|
|
154
|
-
}
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
**Coverage Targets**:
|
|
158
|
-
- Critical modules: 100%
|
|
159
|
-
- High priority: 90%
|
|
160
|
-
- Medium priority: 70%
|
|
161
|
-
- Low priority: 50%
|
|
162
|
-
|
|
163
|
-
### Test Coverage Requirements
|
|
164
|
-
|
|
165
|
-
**Coverage Targets**:
|
|
166
|
-
- Unit tests: 80% line coverage
|
|
167
|
-
- Integration tests: Key workflows covered
|
|
168
|
-
- E2E tests: Critical user paths covered
|
|
169
|
-
|
|
170
|
-
**Required Tests**:
|
|
171
|
-
- All exported functions
|
|
172
|
-
- All public methods
|
|
173
|
-
- Error handling paths
|
|
174
|
-
- Edge cases
|
|
175
|
-
|
|
176
|
-
**Test File Convention**:
|
|
177
|
-
```
|
|
178
|
-
src/auth/login.ts
|
|
179
|
-
→ src/auth/login.test.ts (unit)
|
|
180
|
-
→ src/auth/login.integration.test.ts (integration)
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
### Dependency Management
|
|
184
|
-
|
|
185
|
-
**Best Practices**:
|
|
186
|
-
- Pin major versions (`"^1.2.3"` not `"*"`)
|
|
187
|
-
- Avoid 0.x versions in production
|
|
188
|
-
- Regular security audits (npm audit, snyk)
|
|
189
|
-
- Keep dependencies up-to-date
|
|
190
|
-
- Minimize dependency count
|
|
191
|
-
|
|
192
|
-
**Version Pinning**:
|
|
193
|
-
```json
|
|
194
|
-
{
|
|
195
|
-
"dependencies": {
|
|
196
|
-
"express": "^4.18.0", // ✅ Pinned major version
|
|
197
|
-
"lodash": "*", // ❌ Wildcard
|
|
198
|
-
"legacy-lib": "^0.5.0" // ⚠️ Unstable 0.x
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
### Magic Numbers
|
|
204
|
-
|
|
205
|
-
**Definition**: Numeric literals without clear meaning
|
|
206
|
-
|
|
207
|
-
**Anti-patterns**:
|
|
208
|
-
```javascript
|
|
209
|
-
// ❌ Magic numbers
|
|
210
|
-
if (user.age > 18) { }
|
|
211
|
-
setTimeout(() => {}, 5000);
|
|
212
|
-
buffer = new Array(1048576);
|
|
213
|
-
|
|
214
|
-
// ✅ Named constants
|
|
215
|
-
const LEGAL_AGE = 18;
|
|
216
|
-
const RETRY_DELAY_MS = 5000;
|
|
217
|
-
const BUFFER_SIZE_1MB = 1024 * 1024;
|
|
218
|
-
|
|
219
|
-
if (user.age > LEGAL_AGE) { }
|
|
220
|
-
setTimeout(() => {}, RETRY_DELAY_MS);
|
|
221
|
-
buffer = new Array(BUFFER_SIZE_1MB);
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
**Exceptions** (acceptable magic numbers):
|
|
225
|
-
- 0, 1, -1 (common values)
|
|
226
|
-
- 100, 1000 (obvious scaling factors in context)
|
|
227
|
-
- HTTP status codes (200, 404, 500)
|
|
228
|
-
|
|
229
|
-
## Error Handling Standards
|
|
230
|
-
|
|
231
|
-
### Required Error Handling
|
|
232
|
-
|
|
233
|
-
**Categories**:
|
|
234
|
-
- Network errors (timeout, connection failure)
|
|
235
|
-
- Database errors (query failure, constraint violation)
|
|
236
|
-
- Validation errors (invalid input)
|
|
237
|
-
- Authentication/Authorization errors
|
|
238
|
-
|
|
239
|
-
**Anti-patterns**:
|
|
240
|
-
```javascript
|
|
241
|
-
// ❌ Silent failure
|
|
242
|
-
try {
|
|
243
|
-
await saveUser(user);
|
|
244
|
-
} catch (err) {
|
|
245
|
-
// Empty catch
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// ❌ Generic catch
|
|
249
|
-
try {
|
|
250
|
-
await processPayment(order);
|
|
251
|
-
} catch (err) {
|
|
252
|
-
console.log('Error'); // No details
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// ✅ Proper handling
|
|
256
|
-
try {
|
|
257
|
-
await processPayment(order);
|
|
258
|
-
} catch (err) {
|
|
259
|
-
logger.error('Payment processing failed', { orderId: order.id, error: err });
|
|
260
|
-
throw new PaymentError('Failed to process payment', { cause: err });
|
|
261
|
-
}
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
### Logging Standards
|
|
265
|
-
|
|
266
|
-
**Required Logs**:
|
|
267
|
-
- Authentication attempts (success/failure)
|
|
268
|
-
- Authorization failures
|
|
269
|
-
- Data modifications (create/update/delete)
|
|
270
|
-
- External API calls
|
|
271
|
-
- Errors and exceptions
|
|
272
|
-
|
|
273
|
-
**Log Levels**:
|
|
274
|
-
- **ERROR**: System errors, exceptions
|
|
275
|
-
- **WARN**: Recoverable issues, deprecations
|
|
276
|
-
- **INFO**: Business events, state changes
|
|
277
|
-
- **DEBUG**: Detailed troubleshooting info
|
|
278
|
-
|
|
279
|
-
**Sensitive Data**:
|
|
280
|
-
- Never log: passwords, tokens, credit cards, SSNs
|
|
281
|
-
- Hash/mask: emails, IPs, usernames (in production)
|
|
282
|
-
|
|
283
|
-
## Code Structure Standards
|
|
284
|
-
|
|
285
|
-
### File Organization
|
|
286
|
-
|
|
287
|
-
**Max File Size**: 300 lines (excluding tests)
|
|
288
|
-
**Max Function Size**: 50 lines
|
|
289
|
-
|
|
290
|
-
**Module Structure**:
|
|
291
|
-
```
|
|
292
|
-
module/
|
|
293
|
-
├── index.ts # Public exports
|
|
294
|
-
├── types.ts # Type definitions
|
|
295
|
-
├── constants.ts # Constants
|
|
296
|
-
├── utils.ts # Utilities
|
|
297
|
-
├── service.ts # Business logic
|
|
298
|
-
└── service.test.ts # Tests
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
### Import Organization
|
|
302
|
-
|
|
303
|
-
**Order**:
|
|
304
|
-
1. External dependencies
|
|
305
|
-
2. Internal modules (absolute imports)
|
|
306
|
-
3. Relative imports
|
|
307
|
-
4. Type imports (TypeScript)
|
|
308
|
-
|
|
309
|
-
```typescript
|
|
310
|
-
// ✅ Organized imports
|
|
311
|
-
import express from 'express';
|
|
312
|
-
import { Logger } from 'winston';
|
|
313
|
-
|
|
314
|
-
import { UserService } from '@/services/user';
|
|
315
|
-
import { config } from '@/config';
|
|
316
|
-
|
|
317
|
-
import { validateEmail } from './utils';
|
|
318
|
-
import { UserRepository } from './repository';
|
|
319
|
-
|
|
320
|
-
import type { User, UserCreateInput } from './types';
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
## Scoring System
|
|
324
|
-
|
|
325
|
-
### Overall Score Calculation
|
|
326
|
-
|
|
327
|
-
```
|
|
328
|
-
Overall Score = (
|
|
329
|
-
Security Score × 0.4 +
|
|
330
|
-
Code Quality Score × 0.25 +
|
|
331
|
-
Performance Score × 0.2 +
|
|
332
|
-
Maintainability Score × 0.15
|
|
333
|
-
)
|
|
334
|
-
|
|
335
|
-
Security = 100 - (Critical × 30 + High × 2 + Medium × 0.5)
|
|
336
|
-
Code Quality = 100 - (violations / total_checks × 100)
|
|
337
|
-
Performance = 100 - (issues / potential_issues × 100)
|
|
338
|
-
Maintainability = (doc_coverage × 0.4 + test_coverage × 0.4 + dependency_health × 0.2)
|
|
339
|
-
```
|
|
340
|
-
|
|
341
|
-
### Risk Levels
|
|
342
|
-
|
|
343
|
-
- **LOW**: Score 90-100
|
|
344
|
-
- **MEDIUM**: Score 70-89
|
|
345
|
-
- **HIGH**: Score 50-69
|
|
346
|
-
- **CRITICAL**: Score < 50
|