@jwdobeutechsolutions/dobeutech-claude-code-custom 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.md +174 -0
- package/CONTRIBUTING.md +191 -0
- package/README.md +345 -0
- package/agents/accessibility-auditor.md +315 -0
- package/agents/api-designer.md +265 -0
- package/agents/architect.md +211 -0
- package/agents/build-error-resolver.md +532 -0
- package/agents/ci-cd-generator.md +318 -0
- package/agents/code-reviewer.md +104 -0
- package/agents/database-migrator.md +258 -0
- package/agents/deployment-manager.md +296 -0
- package/agents/doc-updater.md +452 -0
- package/agents/docker-specialist.md +293 -0
- package/agents/e2e-runner.md +708 -0
- package/agents/fullstack-architect.md +293 -0
- package/agents/infrastructure-engineer.md +297 -0
- package/agents/integration-tester.md +320 -0
- package/agents/performance-tester.md +243 -0
- package/agents/planner.md +119 -0
- package/agents/refactor-cleaner.md +306 -0
- package/agents/security-reviewer.md +545 -0
- package/agents/tdd-guide.md +280 -0
- package/agents/unit-test-generator.md +290 -0
- package/bin/claude-config.js +290 -0
- package/commands/api-design.md +55 -0
- package/commands/audit-accessibility.md +37 -0
- package/commands/audit-performance.md +38 -0
- package/commands/audit-security.md +43 -0
- package/commands/build-fix.md +29 -0
- package/commands/changelog.md +31 -0
- package/commands/code-review.md +40 -0
- package/commands/deploy.md +51 -0
- package/commands/docs-api.md +41 -0
- package/commands/e2e.md +363 -0
- package/commands/plan.md +113 -0
- package/commands/refactor-clean.md +28 -0
- package/commands/tdd.md +326 -0
- package/commands/test-coverage.md +27 -0
- package/commands/update-codemaps.md +17 -0
- package/commands/update-docs.md +31 -0
- package/hooks/hooks.json +121 -0
- package/mcp-configs/mcp-servers.json +163 -0
- package/package.json +53 -0
- package/rules/agents.md +49 -0
- package/rules/coding-style.md +70 -0
- package/rules/git-workflow.md +45 -0
- package/rules/hooks.md +46 -0
- package/rules/patterns.md +55 -0
- package/rules/performance.md +47 -0
- package/rules/security.md +36 -0
- package/rules/testing.md +30 -0
- package/scripts/install.js +254 -0
- package/skills/backend-patterns.md +582 -0
- package/skills/clickhouse-io.md +429 -0
- package/skills/coding-standards.md +520 -0
- package/skills/frontend-patterns.md +631 -0
- package/skills/project-guidelines-example.md +345 -0
- package/skills/security-review/SKILL.md +494 -0
- package/skills/tdd-workflow/SKILL.md +409 -0
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: coding-standards
|
|
3
|
+
description: Universal coding standards, best practices, and patterns for TypeScript, JavaScript, React, and Node.js development.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Coding Standards & Best Practices
|
|
7
|
+
|
|
8
|
+
Universal coding standards applicable across all projects.
|
|
9
|
+
|
|
10
|
+
## Code Quality Principles
|
|
11
|
+
|
|
12
|
+
### 1. Readability First
|
|
13
|
+
- Code is read more than written
|
|
14
|
+
- Clear variable and function names
|
|
15
|
+
- Self-documenting code preferred over comments
|
|
16
|
+
- Consistent formatting
|
|
17
|
+
|
|
18
|
+
### 2. KISS (Keep It Simple, Stupid)
|
|
19
|
+
- Simplest solution that works
|
|
20
|
+
- Avoid over-engineering
|
|
21
|
+
- No premature optimization
|
|
22
|
+
- Easy to understand > clever code
|
|
23
|
+
|
|
24
|
+
### 3. DRY (Don't Repeat Yourself)
|
|
25
|
+
- Extract common logic into functions
|
|
26
|
+
- Create reusable components
|
|
27
|
+
- Share utilities across modules
|
|
28
|
+
- Avoid copy-paste programming
|
|
29
|
+
|
|
30
|
+
### 4. YAGNI (You Aren't Gonna Need It)
|
|
31
|
+
- Don't build features before they're needed
|
|
32
|
+
- Avoid speculative generality
|
|
33
|
+
- Add complexity only when required
|
|
34
|
+
- Start simple, refactor when needed
|
|
35
|
+
|
|
36
|
+
## TypeScript/JavaScript Standards
|
|
37
|
+
|
|
38
|
+
### Variable Naming
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
// ✅ GOOD: Descriptive names
|
|
42
|
+
const marketSearchQuery = 'election'
|
|
43
|
+
const isUserAuthenticated = true
|
|
44
|
+
const totalRevenue = 1000
|
|
45
|
+
|
|
46
|
+
// ❌ BAD: Unclear names
|
|
47
|
+
const q = 'election'
|
|
48
|
+
const flag = true
|
|
49
|
+
const x = 1000
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Function Naming
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
// ✅ GOOD: Verb-noun pattern
|
|
56
|
+
async function fetchMarketData(marketId: string) { }
|
|
57
|
+
function calculateSimilarity(a: number[], b: number[]) { }
|
|
58
|
+
function isValidEmail(email: string): boolean { }
|
|
59
|
+
|
|
60
|
+
// ❌ BAD: Unclear or noun-only
|
|
61
|
+
async function market(id: string) { }
|
|
62
|
+
function similarity(a, b) { }
|
|
63
|
+
function email(e) { }
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Immutability Pattern (CRITICAL)
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
// ✅ ALWAYS use spread operator
|
|
70
|
+
const updatedUser = {
|
|
71
|
+
...user,
|
|
72
|
+
name: 'New Name'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const updatedArray = [...items, newItem]
|
|
76
|
+
|
|
77
|
+
// ❌ NEVER mutate directly
|
|
78
|
+
user.name = 'New Name' // BAD
|
|
79
|
+
items.push(newItem) // BAD
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Error Handling
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
// ✅ GOOD: Comprehensive error handling
|
|
86
|
+
async function fetchData(url: string) {
|
|
87
|
+
try {
|
|
88
|
+
const response = await fetch(url)
|
|
89
|
+
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return await response.json()
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error('Fetch failed:', error)
|
|
97
|
+
throw new Error('Failed to fetch data')
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ❌ BAD: No error handling
|
|
102
|
+
async function fetchData(url) {
|
|
103
|
+
const response = await fetch(url)
|
|
104
|
+
return response.json()
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Async/Await Best Practices
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// ✅ GOOD: Parallel execution when possible
|
|
112
|
+
const [users, markets, stats] = await Promise.all([
|
|
113
|
+
fetchUsers(),
|
|
114
|
+
fetchMarkets(),
|
|
115
|
+
fetchStats()
|
|
116
|
+
])
|
|
117
|
+
|
|
118
|
+
// ❌ BAD: Sequential when unnecessary
|
|
119
|
+
const users = await fetchUsers()
|
|
120
|
+
const markets = await fetchMarkets()
|
|
121
|
+
const stats = await fetchStats()
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Type Safety
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
// ✅ GOOD: Proper types
|
|
128
|
+
interface Market {
|
|
129
|
+
id: string
|
|
130
|
+
name: string
|
|
131
|
+
status: 'active' | 'resolved' | 'closed'
|
|
132
|
+
created_at: Date
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function getMarket(id: string): Promise<Market> {
|
|
136
|
+
// Implementation
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ❌ BAD: Using 'any'
|
|
140
|
+
function getMarket(id: any): Promise<any> {
|
|
141
|
+
// Implementation
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## React Best Practices
|
|
146
|
+
|
|
147
|
+
### Component Structure
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
// ✅ GOOD: Functional component with types
|
|
151
|
+
interface ButtonProps {
|
|
152
|
+
children: React.ReactNode
|
|
153
|
+
onClick: () => void
|
|
154
|
+
disabled?: boolean
|
|
155
|
+
variant?: 'primary' | 'secondary'
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function Button({
|
|
159
|
+
children,
|
|
160
|
+
onClick,
|
|
161
|
+
disabled = false,
|
|
162
|
+
variant = 'primary'
|
|
163
|
+
}: ButtonProps) {
|
|
164
|
+
return (
|
|
165
|
+
<button
|
|
166
|
+
onClick={onClick}
|
|
167
|
+
disabled={disabled}
|
|
168
|
+
className={`btn btn-${variant}`}
|
|
169
|
+
>
|
|
170
|
+
{children}
|
|
171
|
+
</button>
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ❌ BAD: No types, unclear structure
|
|
176
|
+
export function Button(props) {
|
|
177
|
+
return <button onClick={props.onClick}>{props.children}</button>
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Custom Hooks
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
// ✅ GOOD: Reusable custom hook
|
|
185
|
+
export function useDebounce<T>(value: T, delay: number): T {
|
|
186
|
+
const [debouncedValue, setDebouncedValue] = useState<T>(value)
|
|
187
|
+
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
const handler = setTimeout(() => {
|
|
190
|
+
setDebouncedValue(value)
|
|
191
|
+
}, delay)
|
|
192
|
+
|
|
193
|
+
return () => clearTimeout(handler)
|
|
194
|
+
}, [value, delay])
|
|
195
|
+
|
|
196
|
+
return debouncedValue
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Usage
|
|
200
|
+
const debouncedQuery = useDebounce(searchQuery, 500)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### State Management
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
// ✅ GOOD: Proper state updates
|
|
207
|
+
const [count, setCount] = useState(0)
|
|
208
|
+
|
|
209
|
+
// Functional update for state based on previous state
|
|
210
|
+
setCount(prev => prev + 1)
|
|
211
|
+
|
|
212
|
+
// ❌ BAD: Direct state reference
|
|
213
|
+
setCount(count + 1) // Can be stale in async scenarios
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Conditional Rendering
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
// ✅ GOOD: Clear conditional rendering
|
|
220
|
+
{isLoading && <Spinner />}
|
|
221
|
+
{error && <ErrorMessage error={error} />}
|
|
222
|
+
{data && <DataDisplay data={data} />}
|
|
223
|
+
|
|
224
|
+
// ❌ BAD: Ternary hell
|
|
225
|
+
{isLoading ? <Spinner /> : error ? <ErrorMessage error={error} /> : data ? <DataDisplay data={data} /> : null}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## API Design Standards
|
|
229
|
+
|
|
230
|
+
### REST API Conventions
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
GET /api/markets # List all markets
|
|
234
|
+
GET /api/markets/:id # Get specific market
|
|
235
|
+
POST /api/markets # Create new market
|
|
236
|
+
PUT /api/markets/:id # Update market (full)
|
|
237
|
+
PATCH /api/markets/:id # Update market (partial)
|
|
238
|
+
DELETE /api/markets/:id # Delete market
|
|
239
|
+
|
|
240
|
+
# Query parameters for filtering
|
|
241
|
+
GET /api/markets?status=active&limit=10&offset=0
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Response Format
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
// ✅ GOOD: Consistent response structure
|
|
248
|
+
interface ApiResponse<T> {
|
|
249
|
+
success: boolean
|
|
250
|
+
data?: T
|
|
251
|
+
error?: string
|
|
252
|
+
meta?: {
|
|
253
|
+
total: number
|
|
254
|
+
page: number
|
|
255
|
+
limit: number
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Success response
|
|
260
|
+
return NextResponse.json({
|
|
261
|
+
success: true,
|
|
262
|
+
data: markets,
|
|
263
|
+
meta: { total: 100, page: 1, limit: 10 }
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
// Error response
|
|
267
|
+
return NextResponse.json({
|
|
268
|
+
success: false,
|
|
269
|
+
error: 'Invalid request'
|
|
270
|
+
}, { status: 400 })
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Input Validation
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import { z } from 'zod'
|
|
277
|
+
|
|
278
|
+
// ✅ GOOD: Schema validation
|
|
279
|
+
const CreateMarketSchema = z.object({
|
|
280
|
+
name: z.string().min(1).max(200),
|
|
281
|
+
description: z.string().min(1).max(2000),
|
|
282
|
+
endDate: z.string().datetime(),
|
|
283
|
+
categories: z.array(z.string()).min(1)
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
export async function POST(request: Request) {
|
|
287
|
+
const body = await request.json()
|
|
288
|
+
|
|
289
|
+
try {
|
|
290
|
+
const validated = CreateMarketSchema.parse(body)
|
|
291
|
+
// Proceed with validated data
|
|
292
|
+
} catch (error) {
|
|
293
|
+
if (error instanceof z.ZodError) {
|
|
294
|
+
return NextResponse.json({
|
|
295
|
+
success: false,
|
|
296
|
+
error: 'Validation failed',
|
|
297
|
+
details: error.errors
|
|
298
|
+
}, { status: 400 })
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## File Organization
|
|
305
|
+
|
|
306
|
+
### Project Structure
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
src/
|
|
310
|
+
├── app/ # Next.js App Router
|
|
311
|
+
│ ├── api/ # API routes
|
|
312
|
+
│ ├── markets/ # Market pages
|
|
313
|
+
│ └── (auth)/ # Auth pages (route groups)
|
|
314
|
+
├── components/ # React components
|
|
315
|
+
│ ├── ui/ # Generic UI components
|
|
316
|
+
│ ├── forms/ # Form components
|
|
317
|
+
│ └── layouts/ # Layout components
|
|
318
|
+
├── hooks/ # Custom React hooks
|
|
319
|
+
├── lib/ # Utilities and configs
|
|
320
|
+
│ ├── api/ # API clients
|
|
321
|
+
│ ├── utils/ # Helper functions
|
|
322
|
+
│ └── constants/ # Constants
|
|
323
|
+
├── types/ # TypeScript types
|
|
324
|
+
└── styles/ # Global styles
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### File Naming
|
|
328
|
+
|
|
329
|
+
```
|
|
330
|
+
components/Button.tsx # PascalCase for components
|
|
331
|
+
hooks/useAuth.ts # camelCase with 'use' prefix
|
|
332
|
+
lib/formatDate.ts # camelCase for utilities
|
|
333
|
+
types/market.types.ts # camelCase with .types suffix
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## Comments & Documentation
|
|
337
|
+
|
|
338
|
+
### When to Comment
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
// ✅ GOOD: Explain WHY, not WHAT
|
|
342
|
+
// Use exponential backoff to avoid overwhelming the API during outages
|
|
343
|
+
const delay = Math.min(1000 * Math.pow(2, retryCount), 30000)
|
|
344
|
+
|
|
345
|
+
// Deliberately using mutation here for performance with large arrays
|
|
346
|
+
items.push(newItem)
|
|
347
|
+
|
|
348
|
+
// ❌ BAD: Stating the obvious
|
|
349
|
+
// Increment counter by 1
|
|
350
|
+
count++
|
|
351
|
+
|
|
352
|
+
// Set name to user's name
|
|
353
|
+
name = user.name
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### JSDoc for Public APIs
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
/**
|
|
360
|
+
* Searches markets using semantic similarity.
|
|
361
|
+
*
|
|
362
|
+
* @param query - Natural language search query
|
|
363
|
+
* @param limit - Maximum number of results (default: 10)
|
|
364
|
+
* @returns Array of markets sorted by similarity score
|
|
365
|
+
* @throws {Error} If OpenAI API fails or Redis unavailable
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```typescript
|
|
369
|
+
* const results = await searchMarkets('election', 5)
|
|
370
|
+
* console.log(results[0].name) // "Trump vs Biden"
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
export async function searchMarkets(
|
|
374
|
+
query: string,
|
|
375
|
+
limit: number = 10
|
|
376
|
+
): Promise<Market[]> {
|
|
377
|
+
// Implementation
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
## Performance Best Practices
|
|
382
|
+
|
|
383
|
+
### Memoization
|
|
384
|
+
|
|
385
|
+
```typescript
|
|
386
|
+
import { useMemo, useCallback } from 'react'
|
|
387
|
+
|
|
388
|
+
// ✅ GOOD: Memoize expensive computations
|
|
389
|
+
const sortedMarkets = useMemo(() => {
|
|
390
|
+
return markets.sort((a, b) => b.volume - a.volume)
|
|
391
|
+
}, [markets])
|
|
392
|
+
|
|
393
|
+
// ✅ GOOD: Memoize callbacks
|
|
394
|
+
const handleSearch = useCallback((query: string) => {
|
|
395
|
+
setSearchQuery(query)
|
|
396
|
+
}, [])
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### Lazy Loading
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
import { lazy, Suspense } from 'react'
|
|
403
|
+
|
|
404
|
+
// ✅ GOOD: Lazy load heavy components
|
|
405
|
+
const HeavyChart = lazy(() => import('./HeavyChart'))
|
|
406
|
+
|
|
407
|
+
export function Dashboard() {
|
|
408
|
+
return (
|
|
409
|
+
<Suspense fallback={<Spinner />}>
|
|
410
|
+
<HeavyChart />
|
|
411
|
+
</Suspense>
|
|
412
|
+
)
|
|
413
|
+
}
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### Database Queries
|
|
417
|
+
|
|
418
|
+
```typescript
|
|
419
|
+
// ✅ GOOD: Select only needed columns
|
|
420
|
+
const { data } = await supabase
|
|
421
|
+
.from('markets')
|
|
422
|
+
.select('id, name, status')
|
|
423
|
+
.limit(10)
|
|
424
|
+
|
|
425
|
+
// ❌ BAD: Select everything
|
|
426
|
+
const { data } = await supabase
|
|
427
|
+
.from('markets')
|
|
428
|
+
.select('*')
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
## Testing Standards
|
|
432
|
+
|
|
433
|
+
### Test Structure (AAA Pattern)
|
|
434
|
+
|
|
435
|
+
```typescript
|
|
436
|
+
test('calculates similarity correctly', () => {
|
|
437
|
+
// Arrange
|
|
438
|
+
const vector1 = [1, 0, 0]
|
|
439
|
+
const vector2 = [0, 1, 0]
|
|
440
|
+
|
|
441
|
+
// Act
|
|
442
|
+
const similarity = calculateCosineSimilarity(vector1, vector2)
|
|
443
|
+
|
|
444
|
+
// Assert
|
|
445
|
+
expect(similarity).toBe(0)
|
|
446
|
+
})
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
### Test Naming
|
|
450
|
+
|
|
451
|
+
```typescript
|
|
452
|
+
// ✅ GOOD: Descriptive test names
|
|
453
|
+
test('returns empty array when no markets match query', () => { })
|
|
454
|
+
test('throws error when OpenAI API key is missing', () => { })
|
|
455
|
+
test('falls back to substring search when Redis unavailable', () => { })
|
|
456
|
+
|
|
457
|
+
// ❌ BAD: Vague test names
|
|
458
|
+
test('works', () => { })
|
|
459
|
+
test('test search', () => { })
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
## Code Smell Detection
|
|
463
|
+
|
|
464
|
+
Watch for these anti-patterns:
|
|
465
|
+
|
|
466
|
+
### 1. Long Functions
|
|
467
|
+
```typescript
|
|
468
|
+
// ❌ BAD: Function > 50 lines
|
|
469
|
+
function processMarketData() {
|
|
470
|
+
// 100 lines of code
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// ✅ GOOD: Split into smaller functions
|
|
474
|
+
function processMarketData() {
|
|
475
|
+
const validated = validateData()
|
|
476
|
+
const transformed = transformData(validated)
|
|
477
|
+
return saveData(transformed)
|
|
478
|
+
}
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
### 2. Deep Nesting
|
|
482
|
+
```typescript
|
|
483
|
+
// ❌ BAD: 5+ levels of nesting
|
|
484
|
+
if (user) {
|
|
485
|
+
if (user.isAdmin) {
|
|
486
|
+
if (market) {
|
|
487
|
+
if (market.isActive) {
|
|
488
|
+
if (hasPermission) {
|
|
489
|
+
// Do something
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// ✅ GOOD: Early returns
|
|
497
|
+
if (!user) return
|
|
498
|
+
if (!user.isAdmin) return
|
|
499
|
+
if (!market) return
|
|
500
|
+
if (!market.isActive) return
|
|
501
|
+
if (!hasPermission) return
|
|
502
|
+
|
|
503
|
+
// Do something
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
### 3. Magic Numbers
|
|
507
|
+
```typescript
|
|
508
|
+
// ❌ BAD: Unexplained numbers
|
|
509
|
+
if (retryCount > 3) { }
|
|
510
|
+
setTimeout(callback, 500)
|
|
511
|
+
|
|
512
|
+
// ✅ GOOD: Named constants
|
|
513
|
+
const MAX_RETRIES = 3
|
|
514
|
+
const DEBOUNCE_DELAY_MS = 500
|
|
515
|
+
|
|
516
|
+
if (retryCount > MAX_RETRIES) { }
|
|
517
|
+
setTimeout(callback, DEBOUNCE_DELAY_MS)
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
**Remember**: Code quality is not negotiable. Clear, maintainable code enables rapid development and confident refactoring.
|