Skip to content

Commit fa238d7

Browse files
committed
chore: ai-config-toolkit sync
1 parent 2052409 commit fa238d7

1 file changed

Lines changed: 252 additions & 0 deletions

File tree

.claude/commands/comment-review.md

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
---
2+
description: Review comments and suggest cleanup (identify unnecessary comments, recommend improvements)
3+
---
4+
5+
# Comment Review Command
6+
7+
## Purpose
8+
9+
Review comment quality and suggest cleanup directions.
10+
11+
**Core Principle**: Code should be self-explanatory. Comments are the last resort.
12+
13+
---
14+
15+
## User Input
16+
17+
```text
18+
$ARGUMENTS
19+
```
20+
21+
**Interpretation Priority**:
22+
23+
1. If $ARGUMENTS provided → Follow user's request (file path, `--all` for entire project, etc.)
24+
2. If empty → Check `git status` for uncommitted changes
25+
3. If no changes → Review latest commit
26+
4. Only review entire project when explicitly requested (`--all` or "review entire codebase")
27+
28+
---
29+
30+
## Comment Principles
31+
32+
### 🚫 Why Avoid Comments
33+
34+
- Comments become lies when code changes but comments don't
35+
- May signal compensating for bad naming
36+
- Most cases can be solved by improving code itself
37+
38+
### ✅ Legitimate Comment Cases
39+
40+
| Category | Description | Examples |
41+
| --------------------------------- | ---------------------------------------- | ----------------------------------------------------------------- |
42+
| **Public API Docs** | JSDoc, TSDoc, GoDoc | `@param`, `@returns`, `@throws` |
43+
| **Business Logic WHY** | Domain knowledge not expressible in code | "Due to regulatory requirements...", "Per customer request..." |
44+
| **External Dependencies** | API limits, policies, quirks | "Stripe API returns max 100 items", "Due to CORS restrictions..." |
45+
| **Performance/Security Warnings** | Intentional technical decisions | "O(n²) but n < 10 guaranteed", "SQL injection prevention" |
46+
| **Complex Patterns** | Regex, algorithm intent | Regex part explanations, algorithm choice reasoning |
47+
| **Legal/License** | Copyright, patents | "MIT License", "Based on Apache algorithm" |
48+
| **TODO/FIXME** | Must include context | `// TODO(username): #123 remove after migration` |
49+
50+
### ⚠️ Business Logic Comment Rules
51+
52+
**Cohesion Principle**: Same business logic explanation should exist in **ONE place only**.
53+
54+
- ❌ Scattered: Same rule repeated across multiple files
55+
- ✅ Cohesive: Documented once in core domain module
56+
57+
---
58+
59+
## Classification Criteria
60+
61+
### ❌ REMOVE (Recommend Deletion)
62+
63+
| Type | Example | Reason |
64+
| --------------------- | ---------------------------------------- | ------------------------- |
65+
| Obvious explanation | `// increment counter` above `counter++` | Code already explains |
66+
| Name compensation | `// get user data` above `getData()` | Rename to `getUserData()` |
67+
| Commented-out code | `// oldFunction()` | Use Git history |
68+
| Section dividers | `// ===== Validation =====` | Extract function instead |
69+
| Type duplication | `// returns string` (TypeScript) | Type system explains |
70+
| Outdated/lying | Doesn't match code | Maintenance hazard |
71+
| Closing brace comment | `} // end if` | Indentation is sufficient |
72+
73+
### ⚠️ IMPROVE (Needs Improvement)
74+
75+
| Type | Problem | Improvement Direction |
76+
| --------------------------- | ---------------------------- | ----------------------------------------- |
77+
| Unclear TODO | `// TODO: fix later` | `// TODO(user): #ticket specific details` |
78+
| WHAT explanation | "Validates user" | Explain WHY: "Due to security policy..." |
79+
| Verbose comment | Paragraph-level explanation | Keep concise |
80+
| Non-standard docs | Plain comment for API | Use JSDoc/TSDoc/GoDoc format |
81+
| Scattered business comments | Same rule in multiple places | Consolidate to one place |
82+
83+
### ✅ KEEP (Maintain)
84+
85+
Matches legitimate comment cases AND:
86+
87+
- Concise and clear
88+
- Synchronized with code
89+
- Explains WHY
90+
- Properly colocated
91+
92+
---
93+
94+
## Workflow
95+
96+
### 1. Determine Analysis Target
97+
98+
```bash
99+
git status --porcelain
100+
```
101+
102+
**Decision Tree**:
103+
104+
1. $ARGUMENTS has specific request → Honor it
105+
2. $ARGUMENTS empty + uncommitted changes exist → Analyze changed files via `git diff`
106+
3. $ARGUMENTS empty + no changes → Analyze latest commit via `git show HEAD`
107+
4. User explicitly requests entire project (`--all`) → Full project scan
108+
109+
### 2. Extract Comments
110+
111+
**Language-specific patterns**:
112+
113+
- TypeScript/JavaScript: `//`, `/* */`, `/** */`
114+
- Go: `//`, `/* */`
115+
- Python: `#`, `""" """`
116+
- HTML/JSX: `{/* */}`, `<!-- -->`
117+
118+
**Include with each comment**:
119+
120+
- Comment content
121+
- File path:line number
122+
- Surrounding code context (±3 lines)
123+
124+
### 3. Classify and Analyze
125+
126+
For each comment:
127+
128+
1. Classification (REMOVE / IMPROVE / KEEP)
129+
2. Reasoning
130+
3. Refactoring suggestion (if applicable)
131+
132+
### 4. Action Decision
133+
134+
| Situation | Action |
135+
| ----------------------------------------------------------- | ----------------------------------------------------------- |
136+
| **Obvious removals** (commented code, trivial explanations) | Fix immediately without asking |
137+
| **Needs discussion** (unclear intent, judgment required) | Suggest in conversation |
138+
| **Entire project review** | Generate formal report with Refactoring Suggestions section |
139+
140+
---
141+
142+
## Output Format
143+
144+
### For Individual Files / Changes (Conversational)
145+
146+
Provide feedback directly in conversation:
147+
148+
- List issues found with file:line references
149+
- Explain reasoning briefly
150+
- Apply obvious fixes immediately
151+
- Suggest improvements for discussion
152+
153+
### For Entire Project Review (Formal Report)
154+
155+
Generate only when reviewing entire project (`--all`):
156+
157+
```markdown
158+
# 📝 Comment Review Report
159+
160+
**Generated**: {timestamp}
161+
**Scope**: Entire Project
162+
**Total Comments Analyzed**: {count}
163+
164+
---
165+
166+
## 📊 Summary
167+
168+
| Category | Count | Percentage |
169+
| ---------- | ----- | ---------- |
170+
| ❌ REMOVE | {n} | {%} |
171+
| ⚠️ IMPROVE | {n} | {%} |
172+
| ✅ KEEP | {n} | {%} |
173+
174+
---
175+
176+
## ❌ REMOVE - Recommend Deletion ({count})
177+
178+
### 1. {file_path}:{line}
179+
180+
... details ...
181+
182+
---
183+
184+
## ⚠️ IMPROVE - Needs Improvement ({count})
185+
186+
### 1. {file_path}:{line}
187+
188+
... details ...
189+
190+
---
191+
192+
## ✅ KEEP - Maintain ({count})
193+
194+
Brief list of legitimate comments found.
195+
196+
---
197+
198+
## 🔧 Refactoring Suggestions
199+
200+
### Extract Function
201+
202+
... suggestions ...
203+
204+
### Rename
205+
206+
... suggestions ...
207+
208+
---
209+
210+
## 📋 Action Checklist
211+
212+
- [ ] Remove {n} unnecessary comments
213+
- [ ] Improve {n} comments
214+
- [ ] Apply {n} refactorings
215+
```
216+
217+
---
218+
219+
## Execution Instructions
220+
221+
1. **Parse Input**: Interpret $ARGUMENTS
222+
2. **Determine Scope**:
223+
- User request → Follow it
224+
- Empty → Check `git status --porcelain`
225+
- Changes exist → Use `git diff` for changed files
226+
- No changes → Use `git show HEAD` for latest commit
227+
3. **Extract Comments**: Search for comment patterns in target files
228+
4. **Classify**: Apply classification criteria
229+
5. **Take Action**:
230+
- Obvious issues → Fix immediately
231+
- Unclear cases → Suggest in conversation
232+
- Entire project → Generate formal report
233+
6. **Language Standards**: Consider JSDoc, TSDoc, GoDoc conventions
234+
7. **Public API**: Recommend keeping documentation comments
235+
236+
---
237+
238+
## Example Usage
239+
240+
```bash
241+
# Review specific file
242+
/comment-review src/utils/parser.ts
243+
244+
# Review current changes (default behavior)
245+
/comment-review
246+
247+
# Review latest commit explicitly
248+
/comment-review --last-commit
249+
250+
# Review entire project (generates formal report)
251+
/comment-review --all
252+
```

0 commit comments

Comments
 (0)