plan-flow-skill 1.0.0
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/commands/create-contract.md +468 -0
- package/.claude/commands/create-plan.md +512 -0
- package/.claude/commands/discovery-plan.md +561 -0
- package/.claude/commands/execute-plan.md +682 -0
- package/.claude/commands/review-code.md +459 -0
- package/.claude/commands/review-pr.md +651 -0
- package/.claude/commands/setup.md +1609 -0
- package/.claude/commands/write-tests.md +543 -0
- package/.claude/rules/core/allowed-patterns.md +175 -0
- package/.claude/rules/core/complexity-scoring.md +225 -0
- package/.claude/rules/core/forbidden-patterns.md +253 -0
- package/.claude/rules/languages/python-patterns.md +6 -0
- package/.claude/rules/languages/typescript-patterns.md +7 -0
- package/.claude/rules/patterns/contract-patterns.md +332 -0
- package/.claude/rules/patterns/discovery-patterns.md +342 -0
- package/.claude/rules/patterns/discovery-templates.md +319 -0
- package/.claude/rules/patterns/jest-patterns.md +482 -0
- package/.claude/rules/patterns/plans-patterns.md +225 -0
- package/.claude/rules/patterns/plans-templates.md +227 -0
- package/.claude/rules/patterns/pytest-patterns.md +457 -0
- package/.claude/rules/patterns/review-code-templates.md +305 -0
- package/.claude/rules/patterns/review-pr-patterns.md +360 -0
- package/.claude/rules/tools/auth-pr-tool.md +30 -0
- package/.claude/rules/tools/interactive-questions-tool.md +235 -0
- package/.claude/rules/tools/jest-testing-tool.md +73 -0
- package/.claude/rules/tools/plan-mode-tool.md +164 -0
- package/.claude/rules/tools/pytest-testing-tool.md +121 -0
- package/.claude/rules/tools/reference-expansion-tool.md +326 -0
- package/LICENSE +21 -0
- package/README.md +167 -0
- package/dist/cli/commands/init.d.ts +6 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +139 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/handlers/claude.d.ts +9 -0
- package/dist/cli/handlers/claude.d.ts.map +1 -0
- package/dist/cli/handlers/claude.js +119 -0
- package/dist/cli/handlers/claude.js.map +1 -0
- package/dist/cli/handlers/codex.d.ts +9 -0
- package/dist/cli/handlers/codex.d.ts.map +1 -0
- package/dist/cli/handlers/codex.js +100 -0
- package/dist/cli/handlers/codex.js.map +1 -0
- package/dist/cli/handlers/cursor.d.ts +8 -0
- package/dist/cli/handlers/cursor.d.ts.map +1 -0
- package/dist/cli/handlers/cursor.js +34 -0
- package/dist/cli/handlers/cursor.js.map +1 -0
- package/dist/cli/handlers/openclaw.d.ts +8 -0
- package/dist/cli/handlers/openclaw.d.ts.map +1 -0
- package/dist/cli/handlers/openclaw.js +34 -0
- package/dist/cli/handlers/openclaw.js.map +1 -0
- package/dist/cli/handlers/shared.d.ts +9 -0
- package/dist/cli/handlers/shared.d.ts.map +1 -0
- package/dist/cli/handlers/shared.js +44 -0
- package/dist/cli/handlers/shared.js.map +1 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +43 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/types.d.ts +26 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +5 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/utils/files.d.ts +37 -0
- package/dist/cli/utils/files.d.ts.map +1 -0
- package/dist/cli/utils/files.js +122 -0
- package/dist/cli/utils/files.js.map +1 -0
- package/dist/cli/utils/logger.d.ts +11 -0
- package/dist/cli/utils/logger.d.ts.map +1 -0
- package/dist/cli/utils/logger.js +34 -0
- package/dist/cli/utils/logger.js.map +1 -0
- package/dist/cli/utils/prompts.d.ts +10 -0
- package/dist/cli/utils/prompts.d.ts.map +1 -0
- package/dist/cli/utils/prompts.js +65 -0
- package/dist/cli/utils/prompts.js.map +1 -0
- package/dist/test/setup.d.ts +5 -0
- package/dist/test/setup.d.ts.map +1 -0
- package/dist/test/setup.js +7 -0
- package/dist/test/setup.js.map +1 -0
- package/package.json +63 -0
- package/rules/core/_index.mdc +89 -0
- package/rules/core/allowed-patterns.mdc +185 -0
- package/rules/core/complexity-scoring.mdc +235 -0
- package/rules/core/forbidden-patterns.mdc +263 -0
- package/rules/languages/_index.mdc +80 -0
- package/rules/languages/python-patterns.mdc +188 -0
- package/rules/languages/typescript-patterns.mdc +128 -0
- package/rules/patterns/_index.mdc +185 -0
- package/rules/patterns/contract-patterns.mdc +344 -0
- package/rules/patterns/discovery-patterns.mdc +354 -0
- package/rules/patterns/discovery-templates.mdc +329 -0
- package/rules/patterns/jest-patterns.mdc +492 -0
- package/rules/patterns/plans-patterns.mdc +237 -0
- package/rules/patterns/plans-templates.mdc +237 -0
- package/rules/patterns/pytest-patterns.mdc +467 -0
- package/rules/patterns/review-code-templates.mdc +315 -0
- package/rules/patterns/review-pr-patterns.mdc +370 -0
- package/rules/skills/_index.mdc +174 -0
- package/rules/skills/create-contract-skill.mdc +239 -0
- package/rules/skills/create-plan-skill.mdc +271 -0
- package/rules/skills/discovery-skill.mdc +295 -0
- package/rules/skills/execute-plan-skill.mdc +388 -0
- package/rules/skills/review-code-skill.mdc +308 -0
- package/rules/skills/review-pr-skill.mdc +496 -0
- package/rules/skills/setup-skill.mdc +923 -0
- package/rules/skills/write-tests-skill.mdc +294 -0
- package/rules/templates/index-template.mdc +126 -0
- package/rules/tools/_index.mdc +114 -0
- package/rules/tools/auth-pr-tool.mdc +362 -0
- package/rules/tools/interactive-questions-tool.mdc +337 -0
- package/rules/tools/jest-testing-tool.mdc +96 -0
- package/rules/tools/plan-mode-tool.mdc +229 -0
- package/rules/tools/pytest-testing-tool.mdc +144 -0
- package/rules/tools/reference-expansion-tool.mdc +338 -0
- package/skills/plan-flow/SKILL.md +109 -0
- package/skills/plan-flow/create-contract/SKILL.md +139 -0
- package/skills/plan-flow/create-plan/SKILL.md +93 -0
- package/skills/plan-flow/discovery/SKILL.md +85 -0
- package/skills/plan-flow/execute-plan/SKILL.md +89 -0
- package/skills/plan-flow/review-code/SKILL.md +100 -0
- package/skills/plan-flow/review-pr/SKILL.md +122 -0
- package/skills/plan-flow/setup/SKILL.md +73 -0
- package/skills/plan-flow/write-tests/SKILL.md +115 -0
- package/templates/shared/AGENTS.md.template +60 -0
- package/templates/shared/CLAUDE.md.template +62 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
|
|
2
|
+
## Complexity Scale
|
|
3
|
+
|
|
4
|
+
| Score | Level | Description | Examples |
|
|
5
|
+
| ----- | --------- | ------------------------------------------ | ---------------------------------------------------------------------- |
|
|
6
|
+
| 0-2 | Trivial | Simple, mechanical changes | Adding a type alias, renaming a variable, adding an import |
|
|
7
|
+
| 3-4 | Low | Straightforward implementation | Creating a simple Zod schema, adding a basic utility function |
|
|
8
|
+
| 5-6 | Medium | Moderate complexity, some decisions | Creating a new component with logic hook, adding a store action |
|
|
9
|
+
| 7-8 | High | Complex implementation, multiple concerns | API route with command pattern, complex state management |
|
|
10
|
+
| 9-10 | Very High | Highly complex, requires careful attention | Streaming implementation, complex algorithms, multi-system integration |
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Scoring Criteria
|
|
15
|
+
|
|
16
|
+
Use these modifiers to calculate the complexity score for each phase:
|
|
17
|
+
|
|
18
|
+
### Positive Modifiers (Add Points)
|
|
19
|
+
|
|
20
|
+
| Modifier | Points |
|
|
21
|
+
| ------------------------------------ | ------ |
|
|
22
|
+
| Each new file to create | +1 |
|
|
23
|
+
| External API integration | +1 |
|
|
24
|
+
| Database operations | +1 |
|
|
25
|
+
| Complex state management | +1 |
|
|
26
|
+
| View/logic separation pattern | +1 |
|
|
27
|
+
| Streaming or real-time features | +2 |
|
|
28
|
+
| Complex business logic or algorithms | +2 |
|
|
29
|
+
| Multi-system integration | +2 |
|
|
30
|
+
| Authentication/authorization logic | +1 |
|
|
31
|
+
| Error handling with recovery | +1 |
|
|
32
|
+
|
|
33
|
+
### Negative Modifiers (Subtract Points)
|
|
34
|
+
|
|
35
|
+
| Modifier | Points |
|
|
36
|
+
| ------------------------------------ | ------ |
|
|
37
|
+
| Purely mechanical/repetitive tasks | -1 |
|
|
38
|
+
| Small modifications to existing code | -1 |
|
|
39
|
+
| Following existing patterns exactly | -1 |
|
|
40
|
+
| Copy/paste with minor changes | -1 |
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Execution Strategy Based on Scores
|
|
45
|
+
|
|
46
|
+
| Total Adjacent Score | Execution Strategy |
|
|
47
|
+
| -------------------- | ------------------------------------------------------------------ |
|
|
48
|
+
| ≤ 6 | **Aggregate**: Execute multiple phases together in one pass |
|
|
49
|
+
| 7-10 | **Cautious**: Execute 1-2 phases, then verify |
|
|
50
|
+
| > 10 | **Sequential**: Execute one phase at a time with full verification |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Aggregation Rules
|
|
55
|
+
|
|
56
|
+
1. **Can aggregate** phases when their combined complexity ≤ 6
|
|
57
|
+
2. **Never aggregate** across a phase with complexity ≥ 8
|
|
58
|
+
3. **Always execute separately**: Tests phase (regardless of score)
|
|
59
|
+
4. **Prefer aggregation** for trivial consecutive phases (0-2 each)
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Examples
|
|
64
|
+
|
|
65
|
+
### Example 1: Aggregatable Phases (Combined ≤ 6)
|
|
66
|
+
|
|
67
|
+
```markdown
|
|
68
|
+
### Phase 1: Types and Schemas
|
|
69
|
+
|
|
70
|
+
**Complexity**: 3/10
|
|
71
|
+
|
|
72
|
+
- [ ] Create WorkflowStep type
|
|
73
|
+
- [ ] Create Zod schema
|
|
74
|
+
|
|
75
|
+
### Phase 2: Utility Functions
|
|
76
|
+
|
|
77
|
+
**Complexity**: 2/10
|
|
78
|
+
|
|
79
|
+
- [ ] Create transformation helper
|
|
80
|
+
|
|
81
|
+
<!-- Combined complexity: 5 → Execute together -->
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Example 2: Must Execute Separately (Phase ≥ 8)
|
|
85
|
+
|
|
86
|
+
```markdown
|
|
87
|
+
### Phase 3: API Route with Streaming
|
|
88
|
+
|
|
89
|
+
**Complexity**: 9/10
|
|
90
|
+
|
|
91
|
+
- [ ] Create streaming endpoint
|
|
92
|
+
- [ ] Handle SSE events
|
|
93
|
+
- [ ] Implement error recovery
|
|
94
|
+
|
|
95
|
+
### Phase 4: UI Components
|
|
96
|
+
|
|
97
|
+
**Complexity**: 6/10
|
|
98
|
+
|
|
99
|
+
- [ ] Create component with view/logic separation
|
|
100
|
+
- [ ] Integrate with store
|
|
101
|
+
|
|
102
|
+
<!-- Phase 3 is ≥ 8, execute separately. Phase 4 starts fresh. -->
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Example 3: Sequential Execution (Total > 10)
|
|
106
|
+
|
|
107
|
+
```markdown
|
|
108
|
+
### Phase 1: Database Schema
|
|
109
|
+
|
|
110
|
+
**Complexity**: 5/10
|
|
111
|
+
|
|
112
|
+
### Phase 2: Backend API
|
|
113
|
+
|
|
114
|
+
**Complexity**: 7/10
|
|
115
|
+
|
|
116
|
+
### Phase 3: Frontend Components
|
|
117
|
+
|
|
118
|
+
**Complexity**: 6/10
|
|
119
|
+
|
|
120
|
+
<!-- Adjacent totals exceed 10, execute one at a time -->
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Phase Format with Complexity
|
|
126
|
+
|
|
127
|
+
Every phase in a plan must include a complexity score:
|
|
128
|
+
|
|
129
|
+
```markdown
|
|
130
|
+
### Phase 1: [Phase Name]
|
|
131
|
+
|
|
132
|
+
**Scope**: [What this phase covers]
|
|
133
|
+
**Complexity**: X/10
|
|
134
|
+
|
|
135
|
+
- [ ] Task 1
|
|
136
|
+
- [ ] Task 2
|
|
137
|
+
|
|
138
|
+
**Build Verification**: Run `npm run build`
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Scoring Guidelines
|
|
144
|
+
|
|
145
|
+
### When in Doubt, Score Higher
|
|
146
|
+
|
|
147
|
+
If uncertain about complexity, err on the side of a higher score. It's better to execute cautiously than to rush through a complex phase.
|
|
148
|
+
|
|
149
|
+
### Re-evaluate During Execution
|
|
150
|
+
|
|
151
|
+
If a phase turns out to be more complex than estimated:
|
|
152
|
+
|
|
153
|
+
1. Stop execution
|
|
154
|
+
2. Update the complexity score in the plan
|
|
155
|
+
3. Adjust execution strategy accordingly
|
|
156
|
+
|
|
157
|
+
### Common Complexity Patterns
|
|
158
|
+
|
|
159
|
+
| Task Type | Typical Score |
|
|
160
|
+
| ------------------------------- | ------------- |
|
|
161
|
+
| Type definitions only | 2-3 |
|
|
162
|
+
| Simple utility function | 2-3 |
|
|
163
|
+
| Zod schema creation | 3-4 |
|
|
164
|
+
| Basic React component | 4-5 |
|
|
165
|
+
| Component with view/logic split | 5-6 |
|
|
166
|
+
| Zustand store actions | 4-5 |
|
|
167
|
+
| REST API route | 5-6 |
|
|
168
|
+
| API route with command pattern | 6-7 |
|
|
169
|
+
| Database operations | 5-7 |
|
|
170
|
+
| Streaming/SSE implementation | 8-9 |
|
|
171
|
+
| Complex algorithm | 7-9 |
|
|
172
|
+
| Multi-service integration | 8-10 |
|
|
173
|
+
| Unit tests | 3-5 |
|
|
174
|
+
| Integration tests | 5-6 |
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Real-World Scoring Examples
|
|
179
|
+
|
|
180
|
+
### Example A: Add a New Form Field
|
|
181
|
+
|
|
182
|
+
**Scenario**: Add an email field to the user registration form.
|
|
183
|
+
|
|
184
|
+
| Modifier | Points | Reason |
|
|
185
|
+
|----------|--------|--------|
|
|
186
|
+
| Modify existing component | -1 | Small modification |
|
|
187
|
+
| Following existing patterns | -1 | Other fields already exist |
|
|
188
|
+
| Add Zod validation | +1 | Schema update |
|
|
189
|
+
| **Total** | **2/10** | Trivial |
|
|
190
|
+
|
|
191
|
+
**Execution**: Can be aggregated with other trivial phases.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
### Example B: Create User Dashboard API
|
|
196
|
+
|
|
197
|
+
**Scenario**: Create an API endpoint that fetches user data with analytics.
|
|
198
|
+
|
|
199
|
+
| Modifier | Points | Reason |
|
|
200
|
+
|----------|--------|--------|
|
|
201
|
+
| New file (route.ts) | +1 | Creating API route |
|
|
202
|
+
| Database operations | +1 | Fetch user data |
|
|
203
|
+
| External API integration | +1 | Analytics service |
|
|
204
|
+
| Error handling with recovery | +1 | Handle service failures |
|
|
205
|
+
| Complex business logic | +2 | Aggregate multiple data sources |
|
|
206
|
+
| **Total** | **6/10** | Medium |
|
|
207
|
+
|
|
208
|
+
**Execution**: Can be aggregated if adjacent phase is ≤ 0.
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
### Example C: Implement Real-time Chat Feature
|
|
213
|
+
|
|
214
|
+
**Scenario**: Add WebSocket-based chat with message persistence.
|
|
215
|
+
|
|
216
|
+
| Modifier | Points | Reason |
|
|
217
|
+
|----------|--------|--------|
|
|
218
|
+
| New files (3 files) | +3 | Route, hook, component |
|
|
219
|
+
| Streaming/real-time | +2 | WebSocket handling |
|
|
220
|
+
| Database operations | +1 | Message persistence |
|
|
221
|
+
| Complex state management | +1 | Chat state with optimistic updates |
|
|
222
|
+
| Multi-system integration | +2 | WebSocket + DB + Auth |
|
|
223
|
+
| **Total** | **9/10** | Very High |
|
|
224
|
+
|
|
225
|
+
**Execution**: Must execute separately. Never aggregate with other phases.
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
|
|
2
|
+
## How to Use This File
|
|
3
|
+
|
|
4
|
+
1. **Add anti-patterns** that cause problems in your codebase
|
|
5
|
+
2. **Show examples** of the problematic code
|
|
6
|
+
3. **Explain why** each pattern is harmful
|
|
7
|
+
4. **Reference the fix** in `.claude/rules/core/allowed-patterns.md` when applicable
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Example Pattern Structure
|
|
12
|
+
|
|
13
|
+
### DON'T: Pattern Name
|
|
14
|
+
|
|
15
|
+
**Problem**: Brief description of why this is problematic.
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
// BAD - Example of the anti-pattern
|
|
19
|
+
const badExample = doThingWrong()
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Why This is Wrong**:
|
|
23
|
+
|
|
24
|
+
- Reason 1
|
|
25
|
+
- Reason 2
|
|
26
|
+
|
|
27
|
+
**Fix**: Description of the correct approach or link to `.claude/rules/core/allowed-patterns.md`.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Example Anti-Patterns
|
|
32
|
+
|
|
33
|
+
### 1. DON'T Use Magic Numbers
|
|
34
|
+
|
|
35
|
+
**Problem**: Hardcoded numbers without context make code hard to understand and maintain.
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
// BAD - What does 86400000 mean?
|
|
39
|
+
setTimeout(cleanup, 86400000)
|
|
40
|
+
|
|
41
|
+
// BAD - Why 5? What if it needs to change?
|
|
42
|
+
if (retryCount > 5) {
|
|
43
|
+
throw new Error('Too many retries')
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Why This is Wrong**:
|
|
48
|
+
|
|
49
|
+
- No context for what the number represents
|
|
50
|
+
- Hard to find and update when requirements change
|
|
51
|
+
- Easy to introduce bugs with typos
|
|
52
|
+
|
|
53
|
+
**Fix**: Use named constants with descriptive names.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
// GOOD
|
|
57
|
+
const ONE_DAY_MS = 24 * 60 * 60 * 1000
|
|
58
|
+
setTimeout(cleanup, ONE_DAY_MS)
|
|
59
|
+
|
|
60
|
+
const MAX_RETRY_ATTEMPTS = 5
|
|
61
|
+
if (retryCount > MAX_RETRY_ATTEMPTS) {
|
|
62
|
+
throw new Error('Too many retries')
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
### 2. DON'T Swallow Errors Silently
|
|
69
|
+
|
|
70
|
+
**Problem**: Catching errors without handling them hides bugs and makes debugging impossible.
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
// BAD - Error is completely ignored
|
|
74
|
+
try {
|
|
75
|
+
await saveData(data)
|
|
76
|
+
} catch (error) {
|
|
77
|
+
// Silent failure - no one knows something went wrong
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// BAD - Generic catch that hides the real issue
|
|
81
|
+
try {
|
|
82
|
+
await complexOperation()
|
|
83
|
+
} catch {
|
|
84
|
+
return null
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Why This is Wrong**:
|
|
89
|
+
|
|
90
|
+
- Bugs go unnoticed until they cause bigger problems
|
|
91
|
+
- Impossible to debug issues in production
|
|
92
|
+
- Users don't know their action failed
|
|
93
|
+
|
|
94
|
+
**Fix**: Always log errors and provide appropriate user feedback.
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
// GOOD
|
|
98
|
+
try {
|
|
99
|
+
await saveData(data)
|
|
100
|
+
} catch (error) {
|
|
101
|
+
logger.error('Failed to save data', { error, data })
|
|
102
|
+
throw new UserFacingError('Unable to save. Please try again.')
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
### 3. DON'T Use Nested Ternaries
|
|
109
|
+
|
|
110
|
+
**Problem**: Deeply nested ternary operators are hard to read and maintain.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
// BAD - Unreadable nested ternaries
|
|
114
|
+
const status = isLoading ? 'loading' : hasError ? 'error' : isComplete ? 'complete' : 'idle'
|
|
115
|
+
|
|
116
|
+
// BAD - Even worse with more nesting
|
|
117
|
+
const message = !user ? 'Not logged in' : !user.verified ? 'Please verify' : user.isPremium ? 'Welcome back, premium user!' : 'Welcome back!'
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**Why This is Wrong**:
|
|
121
|
+
|
|
122
|
+
- Extremely hard to read and understand
|
|
123
|
+
- Easy to introduce bugs when modifying
|
|
124
|
+
- Difficult to add new conditions
|
|
125
|
+
|
|
126
|
+
**Fix**: Use if/else statements, switch statements, or lookup objects.
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
// GOOD - Clear and maintainable
|
|
130
|
+
function getStatus(isLoading: boolean, hasError: boolean, isComplete: boolean) {
|
|
131
|
+
if (isLoading) return 'loading'
|
|
132
|
+
if (hasError) return 'error'
|
|
133
|
+
if (isComplete) return 'complete'
|
|
134
|
+
return 'idle'
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
### 4. DON'T Mutate Function Parameters
|
|
141
|
+
|
|
142
|
+
**Problem**: Mutating parameters causes unexpected side effects and makes code unpredictable.
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
// BAD - Mutating the input array
|
|
146
|
+
function addItem(items: string[], newItem: string) {
|
|
147
|
+
items.push(newItem) // Modifies the original array!
|
|
148
|
+
return items
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// BAD - Mutating object properties
|
|
152
|
+
function updateUser(user: User) {
|
|
153
|
+
user.lastUpdated = new Date() // Modifies the original object!
|
|
154
|
+
return user
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Why This is Wrong**:
|
|
159
|
+
|
|
160
|
+
- Caller doesn't expect their data to change
|
|
161
|
+
- Causes bugs that are hard to track down
|
|
162
|
+
- Breaks immutability expectations in React/Redux
|
|
163
|
+
|
|
164
|
+
**Fix**: Return new objects/arrays instead of mutating.
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
// GOOD - Returns new array
|
|
168
|
+
function addItem(items: string[], newItem: string) {
|
|
169
|
+
return [...items, newItem]
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// GOOD - Returns new object
|
|
173
|
+
function updateUser(user: User) {
|
|
174
|
+
return { ...user, lastUpdated: new Date() }
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
### 5. DON'T Mix Async Patterns
|
|
181
|
+
|
|
182
|
+
**Problem**: Mixing callbacks, promises, and async/await makes code confusing and error-prone.
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
// BAD - Mixing callbacks and promises
|
|
186
|
+
function fetchData(callback) {
|
|
187
|
+
fetch('/api/data')
|
|
188
|
+
.then(res => res.json())
|
|
189
|
+
.then(data => callback(null, data))
|
|
190
|
+
.catch(err => callback(err))
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// BAD - Mixing .then() with async/await
|
|
194
|
+
async function processData() {
|
|
195
|
+
const result = await fetchData()
|
|
196
|
+
return result.then(data => transform(data)) // Mixing patterns!
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**Why This is Wrong**:
|
|
201
|
+
|
|
202
|
+
- Confusing control flow
|
|
203
|
+
- Error handling becomes inconsistent
|
|
204
|
+
- Harder to debug and maintain
|
|
205
|
+
|
|
206
|
+
**Fix**: Use async/await consistently throughout.
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
// GOOD - Consistent async/await
|
|
210
|
+
async function fetchData() {
|
|
211
|
+
const response = await fetch('/api/data')
|
|
212
|
+
return response.json()
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function processData() {
|
|
216
|
+
const data = await fetchData()
|
|
217
|
+
return transform(data)
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Adding Your Anti-Patterns
|
|
224
|
+
|
|
225
|
+
When adding new anti-patterns to this file:
|
|
226
|
+
|
|
227
|
+
1. **Start with "DON'T"** followed by the pattern name
|
|
228
|
+
2. **Describe the problem** briefly
|
|
229
|
+
3. **Provide BAD examples** showing the anti-pattern
|
|
230
|
+
4. **Explain why it's wrong** with a bullet list
|
|
231
|
+
5. **Show the fix** or reference `.claude/rules/core/allowed-patterns.md`
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Template for New Anti-Patterns
|
|
236
|
+
|
|
237
|
+
```markdown
|
|
238
|
+
### DON'T: Pattern Name
|
|
239
|
+
|
|
240
|
+
**Problem**: Brief description of why this is problematic.
|
|
241
|
+
|
|
242
|
+
\`\`\`typescript
|
|
243
|
+
// BAD - Example of the anti-pattern
|
|
244
|
+
const badExample = problematicCode()
|
|
245
|
+
\`\`\`
|
|
246
|
+
|
|
247
|
+
**Why This is Wrong**:
|
|
248
|
+
|
|
249
|
+
- Reason 1
|
|
250
|
+
- Reason 2
|
|
251
|
+
|
|
252
|
+
**Fix**: Description or link to `.claude/rules/core/allowed-patterns.md`.
|
|
253
|
+
```
|