Skip to content

Commit 01bcc75

Browse files
committed
Add no-ai-slop coding standards and rules
- Add comprehensive code quality standards document - Define guidelines for avoiding redundant comments and AI-generated verbose code - Establish TypeScript best practices and type safety standards - Set function design and file structure conventions - Include refactoring guidelines and code review checklist
1 parent ae9925f commit 01bcc75

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

.cursor/rules/no-ai-slop.mdc

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
description: Rules to avoid generating code that is difficult to understand and maintain.
3+
globs:
4+
alwaysApply: true
5+
---
6+
7+
# No AI Slop
8+
9+
## Code Quality Standards
10+
11+
### Avoid Redundant & Unnecessary Comments
12+
13+
- Never add verbose, redundant comments explaining obvious code
14+
- No "helpful" comments like `// Fetch latest data from database`
15+
- No step-by-step explanatory comments for straightforward operations
16+
- Only add comments for complex business logic or non-obvious decisions
17+
- Use self-documenting code with clear function and variable names
18+
19+
### Communication Style
20+
21+
- No emojis in code, comments, or documentation
22+
- No sycophantic language like "you're absolutely right" or excessive agreement
23+
- Be direct and factual in responses
24+
- Focus on technical substance over pleasantries
25+
26+
### Code Organization
27+
28+
- Extract business logic into separate files by feature
29+
- Use specific, descriptive function names that indicate purpose
30+
- Use direct imports instead of barrel files when possible
31+
- No monolithic functions with massive switch statements
32+
- No code duplication - extract common patterns into helpers
33+
34+
### Type Safety
35+
36+
- NO type casting with `as` unless absolutely necessary
37+
- NO `any` types
38+
- Use proper TypeScript types and interfaces, prefer types over interfaces
39+
- Let TypeScript infer types through control flow for better type safety
40+
- Use discriminated unions and proper type guards
41+
42+
### Function Design
43+
44+
- Functions should have single, clear responsibility
45+
- Use domain-driven naming that business stakeholders understand
46+
- Extract helper functions to eliminate duplication
47+
- No functions longer than ~150 lines
48+
- No nested switch statements or complex conditional logic
49+
- Prefer functions over arrow functions
50+
51+
### File Structure
52+
53+
- Organize by domain and feature
54+
- Keep related functionality together
55+
- Use clear, descriptive file names
56+
- No barrel files unless they provide clear value
57+
- No deeply nested directory structures
58+
59+
### Error Handling
60+
61+
- Throw meaningful errors with context
62+
- Re-throw errors for upstream orchestration when logging errors
63+
- No swallowing errors silently
64+
- No generic error messages
65+
66+
### Import/Export Patterns
67+
68+
- Use direct imports for better tree-shaking
69+
- Group imports logically: types, then modules, then utilities
70+
- Use named exports for better tree-shaking
71+
- Avoid default exports unless there's a single primary export
72+
73+
### Database Operations
74+
75+
- Use upsert patterns when appropriate
76+
- Batch related operations together
77+
- Use proper ORM patterns
78+
- No raw SQL unless absolutely necessary
79+
80+
### Refactoring Guidelines
81+
82+
When refactoring legacy code:
83+
84+
1. Extract duplicate logic into helper functions first
85+
2. Separate concerns into focused handlers
86+
3. Replace arrays with Sets for lookups when doing membership checks
87+
4. Remove verbose AI-generated comments
88+
5. Use proper TypeScript types instead of casting
89+
6. Maintain type inference through control flow
90+
91+
## Code Review Checklist
92+
93+
Before submitting code, verify:
94+
95+
- [ ] No redundant comments explaining obvious operations
96+
- [ ] No type casting unless absolutely necessary
97+
- [ ] Functions have single responsibility
98+
- [ ] No code duplication
99+
- [ ] Using Sets for lookups instead of arrays
100+
- [ ] Proper TypeScript types throughout
101+
- [ ] Clear, domain-driven naming
102+
- [ ] No functions over ~150 lines
103+
- [ ] Proper error handling with context
104+
105+
## Examples
106+
107+
### Bad (AI Slop)
108+
109+
```typescript
110+
// Process an API event by syncing data
111+
async function processEvent(event: APIEvent): Promise<void> {
112+
// Skip processing if the event isn't one we're tracking
113+
if (!allowedEvents.includes(event.type)) {
114+
console.debug(`Skipping untracked event: ${event.type}`);
115+
return;
116+
}
117+
118+
// All the events we track have an ID
119+
const eventData = event.data.object as { id?: string };
120+
121+
// ... more slop and verbose comments explaining obvious operations
122+
}
123+
```
124+
125+
### Good (Clean)
126+
127+
```typescript
128+
async function handleEntityUpsertEvent(
129+
event: EntityCreatedEvent | EntityUpdatedEvent,
130+
): Promise<void> {
131+
const entity = event.data.object;
132+
const timestamp = new Date();
133+
await upsertEntity(entity, timestamp);
134+
}
135+
```
136+
137+
Remember: Code should be self-documenting. If you need comments to explain what the code does, the code probably needs to be rewritten to be clearer.

0 commit comments

Comments
 (0)