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.
Files changed (124) hide show
  1. package/.claude/commands/create-contract.md +468 -0
  2. package/.claude/commands/create-plan.md +512 -0
  3. package/.claude/commands/discovery-plan.md +561 -0
  4. package/.claude/commands/execute-plan.md +682 -0
  5. package/.claude/commands/review-code.md +459 -0
  6. package/.claude/commands/review-pr.md +651 -0
  7. package/.claude/commands/setup.md +1609 -0
  8. package/.claude/commands/write-tests.md +543 -0
  9. package/.claude/rules/core/allowed-patterns.md +175 -0
  10. package/.claude/rules/core/complexity-scoring.md +225 -0
  11. package/.claude/rules/core/forbidden-patterns.md +253 -0
  12. package/.claude/rules/languages/python-patterns.md +6 -0
  13. package/.claude/rules/languages/typescript-patterns.md +7 -0
  14. package/.claude/rules/patterns/contract-patterns.md +332 -0
  15. package/.claude/rules/patterns/discovery-patterns.md +342 -0
  16. package/.claude/rules/patterns/discovery-templates.md +319 -0
  17. package/.claude/rules/patterns/jest-patterns.md +482 -0
  18. package/.claude/rules/patterns/plans-patterns.md +225 -0
  19. package/.claude/rules/patterns/plans-templates.md +227 -0
  20. package/.claude/rules/patterns/pytest-patterns.md +457 -0
  21. package/.claude/rules/patterns/review-code-templates.md +305 -0
  22. package/.claude/rules/patterns/review-pr-patterns.md +360 -0
  23. package/.claude/rules/tools/auth-pr-tool.md +30 -0
  24. package/.claude/rules/tools/interactive-questions-tool.md +235 -0
  25. package/.claude/rules/tools/jest-testing-tool.md +73 -0
  26. package/.claude/rules/tools/plan-mode-tool.md +164 -0
  27. package/.claude/rules/tools/pytest-testing-tool.md +121 -0
  28. package/.claude/rules/tools/reference-expansion-tool.md +326 -0
  29. package/LICENSE +21 -0
  30. package/README.md +167 -0
  31. package/dist/cli/commands/init.d.ts +6 -0
  32. package/dist/cli/commands/init.d.ts.map +1 -0
  33. package/dist/cli/commands/init.js +139 -0
  34. package/dist/cli/commands/init.js.map +1 -0
  35. package/dist/cli/handlers/claude.d.ts +9 -0
  36. package/dist/cli/handlers/claude.d.ts.map +1 -0
  37. package/dist/cli/handlers/claude.js +119 -0
  38. package/dist/cli/handlers/claude.js.map +1 -0
  39. package/dist/cli/handlers/codex.d.ts +9 -0
  40. package/dist/cli/handlers/codex.d.ts.map +1 -0
  41. package/dist/cli/handlers/codex.js +100 -0
  42. package/dist/cli/handlers/codex.js.map +1 -0
  43. package/dist/cli/handlers/cursor.d.ts +8 -0
  44. package/dist/cli/handlers/cursor.d.ts.map +1 -0
  45. package/dist/cli/handlers/cursor.js +34 -0
  46. package/dist/cli/handlers/cursor.js.map +1 -0
  47. package/dist/cli/handlers/openclaw.d.ts +8 -0
  48. package/dist/cli/handlers/openclaw.d.ts.map +1 -0
  49. package/dist/cli/handlers/openclaw.js +34 -0
  50. package/dist/cli/handlers/openclaw.js.map +1 -0
  51. package/dist/cli/handlers/shared.d.ts +9 -0
  52. package/dist/cli/handlers/shared.d.ts.map +1 -0
  53. package/dist/cli/handlers/shared.js +44 -0
  54. package/dist/cli/handlers/shared.js.map +1 -0
  55. package/dist/cli/index.d.ts +8 -0
  56. package/dist/cli/index.d.ts.map +1 -0
  57. package/dist/cli/index.js +43 -0
  58. package/dist/cli/index.js.map +1 -0
  59. package/dist/cli/types.d.ts +26 -0
  60. package/dist/cli/types.d.ts.map +1 -0
  61. package/dist/cli/types.js +5 -0
  62. package/dist/cli/types.js.map +1 -0
  63. package/dist/cli/utils/files.d.ts +37 -0
  64. package/dist/cli/utils/files.d.ts.map +1 -0
  65. package/dist/cli/utils/files.js +122 -0
  66. package/dist/cli/utils/files.js.map +1 -0
  67. package/dist/cli/utils/logger.d.ts +11 -0
  68. package/dist/cli/utils/logger.d.ts.map +1 -0
  69. package/dist/cli/utils/logger.js +34 -0
  70. package/dist/cli/utils/logger.js.map +1 -0
  71. package/dist/cli/utils/prompts.d.ts +10 -0
  72. package/dist/cli/utils/prompts.d.ts.map +1 -0
  73. package/dist/cli/utils/prompts.js +65 -0
  74. package/dist/cli/utils/prompts.js.map +1 -0
  75. package/dist/test/setup.d.ts +5 -0
  76. package/dist/test/setup.d.ts.map +1 -0
  77. package/dist/test/setup.js +7 -0
  78. package/dist/test/setup.js.map +1 -0
  79. package/package.json +63 -0
  80. package/rules/core/_index.mdc +89 -0
  81. package/rules/core/allowed-patterns.mdc +185 -0
  82. package/rules/core/complexity-scoring.mdc +235 -0
  83. package/rules/core/forbidden-patterns.mdc +263 -0
  84. package/rules/languages/_index.mdc +80 -0
  85. package/rules/languages/python-patterns.mdc +188 -0
  86. package/rules/languages/typescript-patterns.mdc +128 -0
  87. package/rules/patterns/_index.mdc +185 -0
  88. package/rules/patterns/contract-patterns.mdc +344 -0
  89. package/rules/patterns/discovery-patterns.mdc +354 -0
  90. package/rules/patterns/discovery-templates.mdc +329 -0
  91. package/rules/patterns/jest-patterns.mdc +492 -0
  92. package/rules/patterns/plans-patterns.mdc +237 -0
  93. package/rules/patterns/plans-templates.mdc +237 -0
  94. package/rules/patterns/pytest-patterns.mdc +467 -0
  95. package/rules/patterns/review-code-templates.mdc +315 -0
  96. package/rules/patterns/review-pr-patterns.mdc +370 -0
  97. package/rules/skills/_index.mdc +174 -0
  98. package/rules/skills/create-contract-skill.mdc +239 -0
  99. package/rules/skills/create-plan-skill.mdc +271 -0
  100. package/rules/skills/discovery-skill.mdc +295 -0
  101. package/rules/skills/execute-plan-skill.mdc +388 -0
  102. package/rules/skills/review-code-skill.mdc +308 -0
  103. package/rules/skills/review-pr-skill.mdc +496 -0
  104. package/rules/skills/setup-skill.mdc +923 -0
  105. package/rules/skills/write-tests-skill.mdc +294 -0
  106. package/rules/templates/index-template.mdc +126 -0
  107. package/rules/tools/_index.mdc +114 -0
  108. package/rules/tools/auth-pr-tool.mdc +362 -0
  109. package/rules/tools/interactive-questions-tool.mdc +337 -0
  110. package/rules/tools/jest-testing-tool.mdc +96 -0
  111. package/rules/tools/plan-mode-tool.mdc +229 -0
  112. package/rules/tools/pytest-testing-tool.mdc +144 -0
  113. package/rules/tools/reference-expansion-tool.mdc +338 -0
  114. package/skills/plan-flow/SKILL.md +109 -0
  115. package/skills/plan-flow/create-contract/SKILL.md +139 -0
  116. package/skills/plan-flow/create-plan/SKILL.md +93 -0
  117. package/skills/plan-flow/discovery/SKILL.md +85 -0
  118. package/skills/plan-flow/execute-plan/SKILL.md +89 -0
  119. package/skills/plan-flow/review-code/SKILL.md +100 -0
  120. package/skills/plan-flow/review-pr/SKILL.md +122 -0
  121. package/skills/plan-flow/setup/SKILL.md +73 -0
  122. package/skills/plan-flow/write-tests/SKILL.md +115 -0
  123. package/templates/shared/AGENTS.md.template +60 -0
  124. package/templates/shared/CLAUDE.md.template +62 -0
@@ -0,0 +1,315 @@
1
+ ---
2
+ description: "Output templates for code review documents"
3
+ alwaysApply: false
4
+ ---
5
+
6
+ # Review Code Templates
7
+
8
+ This document contains output templates for the code review skill. For the core workflow, see `.cursor/rules/skills/review-code-skill.mdc`.
9
+
10
+ ---
11
+
12
+ ## Output Format
13
+
14
+ The generated review document should follow this structure:
15
+
16
+ ```markdown
17
+ # Local Code Review: {Description}
18
+
19
+ ## Review Information
20
+
21
+ | Field | Value |
22
+ | -------------- | --------------------- |
23
+ | Date | {date} |
24
+ | Files Reviewed | {number_of_files} |
25
+ | Scope | {all/staged/unstaged} |
26
+ | Language(s) | {detected_languages} |
27
+
28
+ ---
29
+
30
+ ## Changed Files
31
+
32
+ | File | Status | Lines Changed |
33
+ | ------------- | ---------- | ------------- |
34
+ | `{file_path}` | {modified} | +{add}/-{del} |
35
+ | ... | ... | ... |
36
+
37
+ ---
38
+
39
+ ## Reference Implementations Found
40
+
41
+ For each changed file, similar implementations in the codebase:
42
+
43
+ ### {changed_file_path}
44
+
45
+ **Similar implementations found:**
46
+
47
+ | Reference File | Pattern Observed | Consistency |
48
+ | --------------------- | --------------------- | -------------- |
49
+ | `{similar_file_path}` | {pattern_description} | Match/Conflict |
50
+ | ... | ... | ... |
51
+
52
+ **Pattern Notes:**
53
+
54
+ - {observation about how similar code handles the same concern}
55
+
56
+ ---
57
+
58
+ ## Review Summary
59
+
60
+ | Metric | Value |
61
+ | --------------------- | ------------------ |
62
+ | **Total Findings** | {count} |
63
+ | Critical | {critical_count} |
64
+ | Major | {major_count} |
65
+ | Minor | {minor_count} |
66
+ | Suggestion | {suggestion_count} |
67
+ | **Pattern Conflicts** | {conflict_count} |
68
+ | **Total Fix Effort** | {sum_of_scores}/X |
69
+
70
+ ---
71
+
72
+ ## Findings
73
+
74
+ ### Finding 1: {Finding Name}
75
+
76
+ | Field | Value |
77
+ | -------------- | ------------------------------------------------ |
78
+ | File | `{file_path}` |
79
+ | Line | {line_number} |
80
+ | Severity | {Critical/Major/Minor/Suggestion} |
81
+ | Fix Complexity | {X/10} - {Level} |
82
+ | Pattern | {Reference to pattern from rules, if applicable} |
83
+
84
+ **Description**:
85
+ {Detailed explanation of the issue found}
86
+
87
+ **Reference Implementation**:
88
+ See `{reference_file_path}` for how this is handled elsewhere in the codebase.
89
+
90
+ **Suggested Fix**:
91
+ \`\`\`{language}
92
+ // Suggested code improvement
93
+ \`\`\`
94
+
95
+ ---
96
+
97
+ ## Pattern Conflicts
98
+
99
+ This section documents conflicts between the new code and existing codebase patterns.
100
+
101
+ ### Conflict 1: {Conflict Name}
102
+
103
+ | Field | Value |
104
+ | -------------- | -------------------------------------- |
105
+ | New Code File | `{changed_file_path}` |
106
+ | Reference File | `{existing_file_path}` |
107
+ | Pattern Type | {naming/structure/error-handling/etc} |
108
+ | Resolution | {Update new code/Update rules/Discuss} |
109
+
110
+ **New Code Pattern**:
111
+ \`\`\`{language}
112
+ // Pattern used in new code
113
+ \`\`\`
114
+
115
+ **Existing Pattern**:
116
+ \`\`\`{language}
117
+ // Pattern used in existing codebase
118
+ \`\`\`
119
+
120
+ **Recommendation**:
121
+ {Which pattern to use and why}
122
+
123
+ ---
124
+
125
+ ## Rule Update Recommendations
126
+
127
+ When pattern conflicts are found, recommend updates to prevent future inconsistencies.
128
+
129
+ ### Recommended Addition to `allowed-patterns.mdc`
130
+
131
+ If a good pattern is discovered that isn't documented:
132
+
133
+ \`\`\`markdown
134
+
135
+ ### {Pattern Name}
136
+
137
+ {Description of the pattern}
138
+
139
+ \`\`\`typescript
140
+ // Example of the pattern
141
+ \`\`\`
142
+
143
+ **Why**: {Explanation of benefit}
144
+ \`\`\`
145
+
146
+ ### Recommended Addition to `forbidden-patterns.mdc`
147
+
148
+ If an anti-pattern is found that should be avoided:
149
+
150
+ \`\`\`markdown
151
+
152
+ ### DON'T: {Pattern Name}
153
+
154
+ **Problem**: {Description of why this is problematic}
155
+
156
+ \`\`\`typescript
157
+ // BAD - Example of the anti-pattern
158
+ \`\`\`
159
+
160
+ **Why This is Wrong**:
161
+
162
+ - {Reason 1}
163
+ - {Reason 2}
164
+
165
+ **Fix**: {Description of the correct approach}
166
+ \`\`\`
167
+
168
+ ---
169
+
170
+ ## Positive Highlights
171
+
172
+ List any particularly well-written code or good practices observed:
173
+
174
+ - {Highlight 1}
175
+ - {Highlight 2}
176
+
177
+ ---
178
+
179
+ ## Commit Readiness
180
+
181
+ | Status | {Ready to Commit/Needs Changes/Needs Discussion} |
182
+ | ------ | ------------------------------------------------ |
183
+ | Reason | {Brief explanation} |
184
+
185
+ ### Before Committing
186
+
187
+ - [ ] Address all Critical findings
188
+ - [ ] Address all Major findings
189
+ - [ ] Review Pattern Conflicts and decide on resolution
190
+ - [ ] Update rules files if new patterns should be documented
191
+ ```
192
+
193
+ ---
194
+
195
+ ## Example Output
196
+
197
+ ### Pattern Conflict Example
198
+
199
+ ```markdown
200
+ ### Conflict 1: Error Handling Pattern
201
+
202
+ | Field | Value |
203
+ | -------------- | ------------------------------ |
204
+ | New Code File | `src/services/userService.ts` |
205
+ | Reference File | `src/services/orderService.ts` |
206
+ | Pattern Type | error-handling |
207
+ | Resolution | Update new code |
208
+
209
+ **New Code Pattern**:
210
+ \`\`\`typescript
211
+ try {
212
+ await saveUser(data);
213
+ } catch (e) {
214
+ console.log(e); // Silent console log
215
+ return null;
216
+ }
217
+ \`\`\`
218
+
219
+ **Existing Pattern**:
220
+ \`\`\`typescript
221
+ try {
222
+ await saveOrder(data);
223
+ } catch (error) {
224
+ logger.error('Failed to save order', { error, orderId: data.id });
225
+ throw new ServiceError('Unable to save order');
226
+ }
227
+ \`\`\`
228
+
229
+ **Recommendation**:
230
+ Update new code to follow the established error handling pattern from `orderService.ts`. The existing pattern properly logs errors with context and throws a meaningful error for the caller to handle.
231
+ ```
232
+
233
+ ### Rule Update Recommendation Example
234
+
235
+ ```markdown
236
+ ## Rule Update Recommendations
237
+
238
+ ### Recommended Addition to `allowed-patterns.mdc`
239
+
240
+ \`\`\`markdown
241
+
242
+ ### Service Layer Error Handling
243
+
244
+ All service layer functions should handle errors with proper logging and re-throw with meaningful error types.
245
+
246
+ \`\`\`typescript
247
+ // GOOD - Service layer error handling
248
+ try {
249
+ await performOperation(data);
250
+ } catch (error) {
251
+ logger.error('Operation failed', { error, context: data.id });
252
+ throw new ServiceError('Operation failed', { cause: error });
253
+ }
254
+ \`\`\`
255
+
256
+ **Why**: Ensures errors are traceable in logs while providing meaningful errors to callers.
257
+ \`\`\`
258
+
259
+ ### Recommended Addition to `forbidden-patterns.mdc`
260
+
261
+ \`\`\`markdown
262
+
263
+ ### DON'T: Silent Console Logging in Services
264
+
265
+ **Problem**: Using console.log for errors in service layer loses context and makes debugging difficult.
266
+
267
+ \`\`\`typescript
268
+ // BAD - Silent console log
269
+ catch (e) {
270
+ console.log(e);
271
+ return null;
272
+ }
273
+ \`\`\`
274
+
275
+ **Why This is Wrong**:
276
+
277
+ - console.log doesn't persist in production logging systems
278
+ - Returning null hides the error from callers
279
+ - No context about what operation failed
280
+
281
+ **Fix**: Use structured logger and throw meaningful errors.
282
+ \`\`\`
283
+ ```
284
+
285
+ ---
286
+
287
+ ## Finding Example
288
+
289
+ ```markdown
290
+ ### Finding 1: Silent Error Swallowing
291
+
292
+ | Field | Value |
293
+ | -------------- | ----------------------------- |
294
+ | File | `src/services/userService.ts` |
295
+ | Line | 45 |
296
+ | Severity | Major |
297
+ | Fix Complexity | 3/10 - Low |
298
+ | Pattern | forbidden-patterns.mdc |
299
+
300
+ **Description**:
301
+ The catch block catches an error but only logs it to console and returns null. This hides errors from callers and makes debugging difficult.
302
+
303
+ **Reference Implementation**:
304
+ See `src/services/orderService.ts` for proper error handling pattern.
305
+
306
+ **Suggested Fix**:
307
+ \`\`\`typescript
308
+ try {
309
+ await saveUser(data);
310
+ } catch (error) {
311
+ logger.error('Failed to save user', { error, userId: data.id });
312
+ throw new ServiceError('Unable to save user', { cause: error });
313
+ }
314
+ \`\`\`
315
+ ```
@@ -0,0 +1,370 @@
1
+ ---
2
+ description: "PR review checklist and patterns for code reviews"
3
+ alwaysApply: false
4
+ ---
5
+
6
+ # PR Review Patterns
7
+
8
+ This file defines **patterns and guidelines for reviewing Pull Requests**. It integrates with language-specific patterns and references both allowed and forbidden patterns to ensure comprehensive code reviews.
9
+
10
+ ---
11
+
12
+ ## How to Use This File
13
+
14
+ 1. **Analyze the existing codebase** to understand the patterns, conventions, and architectural decisions already established in the project. Look at:
15
+ - Naming conventions used throughout the codebase
16
+ - Code organization and folder structure
17
+ - Error handling approaches
18
+ - Testing patterns and frameworks in use
19
+ - Existing abstractions and utilities
20
+ - Configuration and dependency management style
21
+ 2. **Identify the language(s)** in the PR being reviewed
22
+ 3. **Apply general review patterns** from this file
23
+ 4. **Reference language-specific patterns** based on the codebase:
24
+ - For TypeScript/JavaScript: See `.cursor/rules/languages/typescript-patterns.mdc`
25
+ - For Python: See `.cursor/rules/languages/python-patterns.mdc`
26
+ 5. **Cross-check against forbidden patterns** in `.cursor/rules/core/forbidden-patterns.mdc`
27
+ 6. **Validate alignment with allowed patterns** in `.cursor/rules/core/allowed-patterns.mdc`
28
+
29
+ > **Important:** The patterns already present in the project take precedence. New code should be consistent with the existing codebase style, even if it differs slightly from generic best practices.
30
+
31
+ ---
32
+
33
+ ## General PR Review Checklist
34
+
35
+ ### 1. Code Quality
36
+
37
+ Before approving any PR, verify the following:
38
+
39
+ - [ ] Code follows the patterns defined in `.cursor/rules/core/allowed-patterns.mdc`
40
+ - [ ] Code avoids anti-patterns defined in `.cursor/rules/core/forbidden-patterns.mdc`
41
+ - [ ] Code adheres to language-specific patterns (see Language-Specific Reviews section)
42
+ - [ ] No magic numbers or hardcoded values without context
43
+ - [ ] Error handling is explicit and meaningful
44
+ - [ ] Functions and components follow single responsibility principle
45
+
46
+ ### 2. Naming and Readability
47
+
48
+ - [ ] Variables, functions, and classes have descriptive names
49
+ - [ ] Code is self-documenting where possible
50
+ - [ ] Complex logic has appropriate comments explaining the "why"
51
+ - [ ] Consistent naming conventions throughout the PR
52
+
53
+ ### 3. Testing
54
+
55
+ - [ ] New functionality has corresponding tests
56
+ - [ ] Edge cases are covered
57
+ - [ ] Tests are readable and follow AAA pattern (Arrange, Act, Assert)
58
+ - [ ] No flaky or timing-dependent tests
59
+
60
+ ### 4. Security
61
+
62
+ - [ ] No hardcoded secrets, API keys, or credentials
63
+ - [ ] User inputs are validated and sanitized
64
+ - [ ] Authentication and authorization are properly checked
65
+ - [ ] Sensitive data is handled appropriately
66
+
67
+ ### 5. Performance
68
+
69
+ - [ ] No unnecessary loops or repeated computations
70
+ - [ ] Appropriate use of caching where applicable
71
+ - [ ] No N+1 query problems
72
+ - [ ] Large data sets are handled efficiently
73
+
74
+ ---
75
+
76
+ ## Language-Specific Reviews
77
+
78
+ ### TypeScript/JavaScript PRs
79
+
80
+ When reviewing TypeScript or JavaScript code, apply these additional checks from `.cursor/rules/languages/typescript-patterns.mdc`:
81
+
82
+ **Type Safety:**
83
+
84
+ - [ ] Strict type-checking is enabled and followed
85
+ - [ ] No use of `any` type (use `unknown` with type guards instead)
86
+ - [ ] Interfaces are used for object shapes
87
+ - [ ] Discriminated unions for state management
88
+ - [ ] Proper use of generics for reusable components
89
+
90
+ **Patterns to Look For:**
91
+
92
+ ```typescript
93
+ // GOOD - Discriminated unions for state
94
+ type RequestState =
95
+ | { status: "idle" }
96
+ | { status: "loading" }
97
+ | { status: "success"; data: User }
98
+ | { status: "error"; error: Error };
99
+
100
+ // BAD - Loose typing with any
101
+ let value: any;
102
+ ```
103
+
104
+ **Null Safety:**
105
+
106
+ - [ ] Optional chaining is used appropriately (`?.`)
107
+ - [ ] Nullish coalescing is used (`??`)
108
+ - [ ] Type guards are implemented for runtime type checking
109
+
110
+ **Immutability:**
111
+
112
+ - [ ] `readonly` is used where mutation should be prevented
113
+ - [ ] Arrays are not mutated directly; spread operators or `.map()` are used
114
+
115
+ **Reference:** See `.cursor/rules/languages/typescript-patterns.mdc` for the complete TypeScript best practices.
116
+
117
+ ---
118
+
119
+ ### Python PRs
120
+
121
+ When reviewing Python code, apply these additional checks from `.cursor/rules/languages/python-patterns.mdc`:
122
+
123
+ **Type Hints:**
124
+
125
+ - [ ] Function signatures have type hints
126
+ - [ ] Return types are specified
127
+ - [ ] Complex types use `typing` module (e.g., `List`, `Dict`, `Optional`)
128
+
129
+ **Patterns to Look For:**
130
+
131
+ ```python
132
+ # GOOD - Type hints with docstrings
133
+ def fetch_user(user_id: str) -> Optional[User]:
134
+ """Fetch a user by their ID.
135
+
136
+ Args:
137
+ user_id: The unique identifier of the user.
138
+
139
+ Returns:
140
+ The user if found, None otherwise.
141
+ """
142
+ pass
143
+
144
+ # BAD - No type hints, unclear function signature
145
+ def fetch_user(user_id):
146
+ pass
147
+ ```
148
+
149
+ **Error Handling:**
150
+
151
+ - [ ] Specific exceptions are caught (not bare `except:`)
152
+ - [ ] Context managers are used for resources (`with` statement)
153
+ - [ ] Errors are logged with appropriate context
154
+
155
+ **Code Style:**
156
+
157
+ - [ ] PEP 8 compliance
158
+ - [ ] Meaningful variable and function names (snake_case)
159
+ - [ ] Docstrings for public functions and classes
160
+ - [ ] No circular imports
161
+
162
+ **Reference:** See `.cursor/rules/languages/python-patterns.mdc` for the complete Python best practices.
163
+
164
+ ---
165
+
166
+ ## Forbidden Patterns to Catch in Reviews
167
+
168
+ Always flag these anti-patterns from `.cursor/rules/core/forbidden-patterns.mdc`:
169
+
170
+ ### 1. Magic Numbers
171
+
172
+ ```typescript
173
+ // FLAG THIS
174
+ setTimeout(cleanup, 86400000)
175
+ if (retryCount > 5) { ... }
176
+
177
+ // SUGGEST THIS
178
+ const ONE_DAY_MS = 24 * 60 * 60 * 1000
179
+ setTimeout(cleanup, ONE_DAY_MS)
180
+ ```
181
+
182
+ ### 2. Silent Error Swallowing
183
+
184
+ ```typescript
185
+ // FLAG THIS
186
+ try {
187
+ await saveData(data);
188
+ } catch (error) {
189
+ // Silent failure
190
+ }
191
+
192
+ // SUGGEST THIS
193
+ try {
194
+ await saveData(data);
195
+ } catch (error) {
196
+ logger.error("Failed to save data", { error, data });
197
+ throw new UserFacingError("Unable to save. Please try again.");
198
+ }
199
+ ```
200
+
201
+ ### 3. Nested Ternaries
202
+
203
+ ```typescript
204
+ // FLAG THIS
205
+ const status = isLoading
206
+ ? "loading"
207
+ : hasError
208
+ ? "error"
209
+ : isComplete
210
+ ? "complete"
211
+ : "idle";
212
+
213
+ // SUGGEST THIS
214
+ function getStatus(isLoading: boolean, hasError: boolean, isComplete: boolean) {
215
+ if (isLoading) return "loading";
216
+ if (hasError) return "error";
217
+ if (isComplete) return "complete";
218
+ return "idle";
219
+ }
220
+ ```
221
+
222
+ ### 4. Parameter Mutation
223
+
224
+ ```typescript
225
+ // FLAG THIS
226
+ function addItem(items: string[], newItem: string) {
227
+ items.push(newItem); // Mutates original!
228
+ return items;
229
+ }
230
+
231
+ // SUGGEST THIS
232
+ function addItem(items: string[], newItem: string) {
233
+ return [...items, newItem];
234
+ }
235
+ ```
236
+
237
+ ### 5. Mixed Async Patterns
238
+
239
+ ```typescript
240
+ // FLAG THIS
241
+ async function processData() {
242
+ const result = await fetchData();
243
+ return result.then((data) => transform(data));
244
+ }
245
+
246
+ // SUGGEST THIS
247
+ async function processData() {
248
+ const data = await fetchData();
249
+ return transform(data);
250
+ }
251
+ ```
252
+
253
+ ---
254
+
255
+ ## Allowed Patterns to Encourage
256
+
257
+ Reference `.cursor/rules/core/allowed-patterns.mdc` and encourage these practices:
258
+
259
+ ### 1. Descriptive Naming
260
+
261
+ ```typescript
262
+ // ENCOURAGE
263
+ function calculateOrderTotal(items: OrderItem[]): number;
264
+ function fetchUserProfile(userId: string): Promise<User>;
265
+ const isAuthenticated = checkAuthStatus();
266
+ ```
267
+
268
+ ### 2. Single Responsibility
269
+
270
+ ```typescript
271
+ // ENCOURAGE - Focused, testable functions
272
+ function formatCurrency(amount: number): string {
273
+ return new Intl.NumberFormat("en-US", {
274
+ style: "currency",
275
+ currency: "USD",
276
+ }).format(amount);
277
+ }
278
+ ```
279
+
280
+ ### 3. Explicit Error Handling
281
+
282
+ ```typescript
283
+ // ENCOURAGE
284
+ async function fetchData(url: string) {
285
+ try {
286
+ const response = await fetch(url);
287
+ if (!response.ok) {
288
+ throw new ApiError(`Request failed: ${response.status}`);
289
+ }
290
+ return response.json();
291
+ } catch (error) {
292
+ logger.error("Failed to fetch data", { url, error });
293
+ throw error;
294
+ }
295
+ }
296
+ ```
297
+
298
+ ### 4. Consistent Code Organization
299
+
300
+ ```
301
+ // ENCOURAGE this structure
302
+ src/
303
+ ├── components/ # UI components
304
+ ├── hooks/ # Custom React hooks
305
+ ├── utils/ # Utility functions
306
+ ├── types/ # TypeScript type definitions
307
+ ├── services/ # API and external service integrations
308
+ └── stores/ # State management
309
+ ```
310
+
311
+ ---
312
+
313
+ ## Review Comment Templates
314
+
315
+ Use these templates for consistent review feedback:
316
+
317
+ ### Suggesting a Pattern Change
318
+
319
+ ```markdown
320
+ **Pattern Suggestion**: This code uses [anti-pattern name].
321
+
322
+ Consider refactoring to:
323
+ \`\`\`typescript
324
+ // Suggested improvement
325
+ \`\`\`
326
+
327
+ Reference: See `.cursor/rules/core/forbidden-patterns.mdc` for details on why this pattern is problematic.
328
+ ```
329
+
330
+ ### Requesting Type Safety Improvements
331
+
332
+ ```markdown
333
+ **Type Safety**: The use of `any` here bypasses TypeScript's type checking.
334
+
335
+ Consider using `unknown` with a type guard, or define a specific interface.
336
+
337
+ Reference: See `.cursor/rules/languages/typescript-patterns.mdc` section on "Avoid the `any` Type".
338
+ ```
339
+
340
+ ### Flagging Missing Error Handling
341
+
342
+ ```markdown
343
+ **Error Handling**: This error is being swallowed silently.
344
+
345
+ Please add appropriate logging and user feedback. See `.cursor/rules/core/allowed-patterns.mdc` for error handling guidelines.
346
+ ```
347
+
348
+ ---
349
+
350
+ ## PR Approval Criteria
351
+
352
+ A PR should only be approved when:
353
+
354
+ 1. **No forbidden patterns** are present (or have been addressed)
355
+ 2. **Allowed patterns** are followed where applicable
356
+ 3. **Language-specific patterns** are adhered to
357
+ 4. **Tests** are present and passing
358
+ 5. **No security concerns** have been identified
359
+ 6. **Code is readable** and maintainable
360
+
361
+ ---
362
+
363
+ ## Quick Reference: Pattern Files
364
+
365
+ | File | Purpose | When to Reference |
366
+ | ------------------------- | ------------------------------ | ------------------------------ |
367
+ | `.cursor/rules/core/forbidden-patterns.mdc` | Anti-patterns to avoid | When flagging problematic code |
368
+ | `.cursor/rules/core/allowed-patterns.mdc` | Best practices to follow | When suggesting improvements |
369
+ | `.cursor/rules/languages/typescript-patterns.mdc` | TypeScript-specific guidelines | When reviewing TS/JS code |
370
+ | `.cursor/rules/languages/python-patterns.mdc` | Python-specific guidelines | When reviewing Python code |