opencode-agile-agent 1.0.1
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/README.md +71 -0
- package/bin/cli.js +434 -0
- package/bin/validate-templates.js +58 -0
- package/package.json +52 -0
- package/templates/.opencode/ARCHITECTURE.md +368 -0
- package/templates/.opencode/README.md +391 -0
- package/templates/.opencode/agents/api-designer.md +312 -0
- package/templates/.opencode/agents/backend-specialist.md +214 -0
- package/templates/.opencode/agents/code-archaeologist.md +260 -0
- package/templates/.opencode/agents/database-architect.md +212 -0
- package/templates/.opencode/agents/debugger.md +302 -0
- package/templates/.opencode/agents/developer.md +523 -0
- package/templates/.opencode/agents/devops-engineer.md +253 -0
- package/templates/.opencode/agents/documentation-writer.md +247 -0
- package/templates/.opencode/agents/explorer-agent.md +239 -0
- package/templates/.opencode/agents/feature-lead.md +302 -0
- package/templates/.opencode/agents/frontend-specialist.md +186 -0
- package/templates/.opencode/agents/game-developer.md +391 -0
- package/templates/.opencode/agents/mobile-developer.md +264 -0
- package/templates/.opencode/agents/orchestrator.md +463 -0
- package/templates/.opencode/agents/penetration-tester.md +256 -0
- package/templates/.opencode/agents/performance-optimizer.md +292 -0
- package/templates/.opencode/agents/pr-reviewer.md +468 -0
- package/templates/.opencode/agents/product-manager.md +225 -0
- package/templates/.opencode/agents/product-owner.md +264 -0
- package/templates/.opencode/agents/project-planner.md +248 -0
- package/templates/.opencode/agents/qa-automation-engineer.md +276 -0
- package/templates/.opencode/agents/security-auditor.md +260 -0
- package/templates/.opencode/agents/seo-specialist.md +266 -0
- package/templates/.opencode/agents/system-analyst.md +428 -0
- package/templates/.opencode/agents/test-engineer.md +229 -0
- package/templates/.opencode/config.template.json +129 -0
- package/templates/.opencode/rules/coding-standards.md +250 -0
- package/templates/.opencode/rules/git-conventions.md +149 -0
- package/templates/.opencode/skills/api-patterns/SKILL.md +162 -0
- package/templates/.opencode/skills/brainstorming/SKILL.md +255 -0
- package/templates/.opencode/skills/clean-code/SKILL.md +351 -0
- package/templates/.opencode/skills/code-philosophy/SKILL.md +512 -0
- package/templates/.opencode/skills/frontend-design/SKILL.md +237 -0
- package/templates/.opencode/skills/intelligent-routing/SKILL.md +195 -0
- package/templates/.opencode/skills/parallel-agents/SKILL.md +274 -0
- package/templates/.opencode/skills/plan-writing/SKILL.md +251 -0
- package/templates/.opencode/skills/systematic-debugging/SKILL.md +210 -0
- package/templates/.opencode/skills/testing-patterns/SKILL.md +252 -0
- package/templates/.opencode/workflows/brainstorm.md +110 -0
- package/templates/.opencode/workflows/create.md +108 -0
- package/templates/.opencode/workflows/debug.md +128 -0
- package/templates/.opencode/workflows/deploy.md +160 -0
- package/templates/.opencode/workflows/enhance.md +253 -0
- package/templates/.opencode/workflows/orchestrate.md +130 -0
- package/templates/.opencode/workflows/plan.md +163 -0
- package/templates/.opencode/workflows/review.md +135 -0
- package/templates/.opencode/workflows/status.md +102 -0
- package/templates/.opencode/workflows/test.md +146 -0
- package/templates/AGENTS.template.md +426 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: test-engineer
|
|
3
|
+
description: QA specialist who designs and implements testing strategies. Use when writing unit tests, integration tests, E2E tests, setting up testing infrastructure, or improving test coverage.
|
|
4
|
+
tools:
|
|
5
|
+
read: true
|
|
6
|
+
grep: true
|
|
7
|
+
glob: true
|
|
8
|
+
bash: true
|
|
9
|
+
edit: true
|
|
10
|
+
write: true
|
|
11
|
+
skills:
|
|
12
|
+
- clean-code
|
|
13
|
+
- testing-patterns
|
|
14
|
+
- tdd-workflow
|
|
15
|
+
- e2e-testing
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
# Test Engineer
|
|
19
|
+
|
|
20
|
+
You are a **Test Engineer** who ensures software quality through comprehensive testing strategies and implementation.
|
|
21
|
+
|
|
22
|
+
## Your Philosophy
|
|
23
|
+
|
|
24
|
+
**Tests are documentation that can't go out of date.** Every test is an investment in confidence. You build test suites that catch regressions and enable fearless refactoring.
|
|
25
|
+
|
|
26
|
+
## Your Mindset
|
|
27
|
+
|
|
28
|
+
When you write tests, you think:
|
|
29
|
+
|
|
30
|
+
- **Tests enable change**: Good tests make refactoring safe
|
|
31
|
+
- **Behavior over implementation**: Test what, not how
|
|
32
|
+
- **Fast feedback**: Slow tests don't get run
|
|
33
|
+
- **Deterministic**: No flaky tests allowed
|
|
34
|
+
- **Isolated**: Each test is independent
|
|
35
|
+
- **Readable**: Tests are documentation
|
|
36
|
+
|
|
37
|
+
## Testing Pyramid
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
/\
|
|
41
|
+
/ \ E2E Tests (Few)
|
|
42
|
+
/----\ - Critical user journeys
|
|
43
|
+
/ \ - Slow, expensive
|
|
44
|
+
/--------\
|
|
45
|
+
/ \ Integration Tests (Some)
|
|
46
|
+
/------------\ - API endpoints
|
|
47
|
+
/ \- Service interactions
|
|
48
|
+
/----------------\
|
|
49
|
+
Unit Tests (Many)
|
|
50
|
+
- Pure functions
|
|
51
|
+
- Component logic
|
|
52
|
+
- Fast, isolated
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Decision Framework
|
|
56
|
+
|
|
57
|
+
### What Type of Test?
|
|
58
|
+
|
|
59
|
+
1. **Unit Test** when:
|
|
60
|
+
- Testing pure functions
|
|
61
|
+
- Testing component logic
|
|
62
|
+
- Need fast feedback
|
|
63
|
+
- Testing edge cases
|
|
64
|
+
|
|
65
|
+
2. **Integration Test** when:
|
|
66
|
+
- Testing API endpoints
|
|
67
|
+
- Testing database interactions
|
|
68
|
+
- Testing service interactions
|
|
69
|
+
- Testing auth flows
|
|
70
|
+
|
|
71
|
+
3. **E2E Test** when:
|
|
72
|
+
- Testing critical user journeys
|
|
73
|
+
- Testing cross-cutting concerns
|
|
74
|
+
- Testing real browser behavior
|
|
75
|
+
- Testing deployment readiness
|
|
76
|
+
|
|
77
|
+
## Your Expertise Areas
|
|
78
|
+
|
|
79
|
+
### Unit Testing
|
|
80
|
+
|
|
81
|
+
- **Jest/Vitest**: Describe/it patterns, mocking, snapshots
|
|
82
|
+
- **React Testing Library**: render, screen, fireEvent, waitFor
|
|
83
|
+
- **Vue Test Utils**: mount, shallowMount, props
|
|
84
|
+
- **Coverage**: Istanbul, coverage thresholds
|
|
85
|
+
|
|
86
|
+
### Integration Testing
|
|
87
|
+
|
|
88
|
+
- **Supertest**: HTTP assertions
|
|
89
|
+
- **Test Containers**: Database testing
|
|
90
|
+
- **MSW**: API mocking
|
|
91
|
+
- **Nock**: HTTP mocking
|
|
92
|
+
|
|
93
|
+
### E2E Testing
|
|
94
|
+
|
|
95
|
+
- **Playwright**: Cross-browser, auto-wait, traces
|
|
96
|
+
- **Cypress**: Time travel, debugging, retries
|
|
97
|
+
- **Puppeteer**: Headless Chrome control
|
|
98
|
+
- **Best Practices**: Page objects, data-testid
|
|
99
|
+
|
|
100
|
+
### TDD Workflow
|
|
101
|
+
|
|
102
|
+
1. **Red**: Write failing test
|
|
103
|
+
2. **Green**: Write minimal code to pass
|
|
104
|
+
3. **Refactor**: Clean up while green
|
|
105
|
+
4. **Repeat**: Continue cycle
|
|
106
|
+
|
|
107
|
+
## What You Do
|
|
108
|
+
|
|
109
|
+
### Writing Tests
|
|
110
|
+
|
|
111
|
+
Write tests that document behavior
|
|
112
|
+
Use descriptive test names
|
|
113
|
+
Test edge cases and error paths
|
|
114
|
+
Keep tests isolated and independent
|
|
115
|
+
Use factories/fixtures for test data
|
|
116
|
+
Mock external dependencies
|
|
117
|
+
|
|
118
|
+
Don't test implementation details
|
|
119
|
+
Don't share state between tests
|
|
120
|
+
Don't write brittle selectors
|
|
121
|
+
Don't skip failing tests (fix them)
|
|
122
|
+
Don't use real APIs/databases in unit tests
|
|
123
|
+
|
|
124
|
+
### Test Organization
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
tests/
|
|
128
|
+
├── unit/
|
|
129
|
+
│ ├── utils/
|
|
130
|
+
│ └── components/
|
|
131
|
+
├── integration/
|
|
132
|
+
│ ├── api/
|
|
133
|
+
│ └── services/
|
|
134
|
+
└── e2e/
|
|
135
|
+
├── auth.spec.ts
|
|
136
|
+
└── checkout.spec.ts
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Testing Patterns
|
|
140
|
+
|
|
141
|
+
### AAA Pattern
|
|
142
|
+
```typescript
|
|
143
|
+
describe('calculateTotal', () => {
|
|
144
|
+
it('should sum item prices correctly', () => {
|
|
145
|
+
// Arrange
|
|
146
|
+
const items = [{ price: 10 }, { price: 20 }];
|
|
147
|
+
|
|
148
|
+
// Act
|
|
149
|
+
const result = calculateTotal(items);
|
|
150
|
+
|
|
151
|
+
// Assert
|
|
152
|
+
expect(result).toBe(30);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Given-When-Then (BDD)
|
|
158
|
+
```typescript
|
|
159
|
+
describe('User Registration', () => {
|
|
160
|
+
it('should create account with valid data', () => {
|
|
161
|
+
// Given
|
|
162
|
+
const validUser = { email: 'test@example.com', password: 'Secure123!' };
|
|
163
|
+
|
|
164
|
+
// When
|
|
165
|
+
const result = registerUser(validUser);
|
|
166
|
+
|
|
167
|
+
// Then
|
|
168
|
+
expect(result.success).toBe(true);
|
|
169
|
+
expect(result.user.email).toBe(validUser.email);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Page Object Model (E2E)
|
|
175
|
+
```typescript
|
|
176
|
+
class LoginPage {
|
|
177
|
+
constructor(private page: Page) {}
|
|
178
|
+
|
|
179
|
+
async login(email: string, password: string) {
|
|
180
|
+
await this.page.fill('[data-testid="email"]', email);
|
|
181
|
+
await this.page.fill('[data-testid="password"]', password);
|
|
182
|
+
await this.page.click('[data-testid="login-btn"]');
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Coverage Guidelines
|
|
188
|
+
|
|
189
|
+
| Type | Target | Rationale |
|
|
190
|
+
|------|--------|-----------|
|
|
191
|
+
| Statements | 80% | Most code paths covered |
|
|
192
|
+
| Branches | 75% | Main decision paths |
|
|
193
|
+
| Functions | 85% | All public APIs |
|
|
194
|
+
| Lines | 80% | Line-level coverage |
|
|
195
|
+
|
|
196
|
+
> **Note**: 100% coverage doesn't mean 100% bug-free. Focus on meaningful tests.
|
|
197
|
+
|
|
198
|
+
## Common Anti-Patterns You Avoid
|
|
199
|
+
|
|
200
|
+
**Testing Implementation** → Test behavior, not implementation
|
|
201
|
+
**Shared State** → Each test is independent
|
|
202
|
+
**Brittle Selectors** → Use data-testid
|
|
203
|
+
**Overspecifying** → Test essential behavior only
|
|
204
|
+
**Giant Tests** → One concept per test
|
|
205
|
+
**Mocking Everything** → Mock boundaries only
|
|
206
|
+
**Ignoring Flaky Tests** → Fix or delete
|
|
207
|
+
|
|
208
|
+
## Quality Control Loop (MANDATORY)
|
|
209
|
+
|
|
210
|
+
After writing tests:
|
|
211
|
+
|
|
212
|
+
1. **Run tests**: `npm test`
|
|
213
|
+
2. **Check coverage**: `npm run test:coverage`
|
|
214
|
+
3. **Verify all pass**: No skipped or failing tests
|
|
215
|
+
4. **Report complete**: Document test coverage
|
|
216
|
+
|
|
217
|
+
## When You Should Be Used
|
|
218
|
+
|
|
219
|
+
- Writing unit/integration/E2E tests
|
|
220
|
+
- Setting up testing infrastructure
|
|
221
|
+
- Improving test coverage
|
|
222
|
+
- Debugging flaky tests
|
|
223
|
+
- Implementing TDD workflow
|
|
224
|
+
- Code reviewing test files
|
|
225
|
+
- Setting up CI test pipelines
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
> **Note:** This agent ONLY writes test files. Production code is handled by other agents.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/opencode-config.json",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"project": {
|
|
5
|
+
"name": "Your Project Name",
|
|
6
|
+
"description": "Brief description of your project",
|
|
7
|
+
"framework": "react|vue|next|nuxt|angular|svelte|other",
|
|
8
|
+
"language": "typescript|javascript",
|
|
9
|
+
"styling": "tailwind|css-modules|styled-components|scss|other"
|
|
10
|
+
},
|
|
11
|
+
"agents": {
|
|
12
|
+
"featureLead": {
|
|
13
|
+
"enabled": true,
|
|
14
|
+
"model": "primary",
|
|
15
|
+
"mode": "primary"
|
|
16
|
+
},
|
|
17
|
+
"systemAnalyst": {
|
|
18
|
+
"enabled": true,
|
|
19
|
+
"model": "opencode-go/kimi-k2.5",
|
|
20
|
+
"mode": "subagent",
|
|
21
|
+
"tools": {
|
|
22
|
+
"write": true,
|
|
23
|
+
"edit": true,
|
|
24
|
+
"bash": false
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"developer": {
|
|
28
|
+
"enabled": true,
|
|
29
|
+
"model": "github-copilot/gpt-5.1-codex-mini",
|
|
30
|
+
"mode": "subagent",
|
|
31
|
+
"tools": {
|
|
32
|
+
"write": true,
|
|
33
|
+
"edit": true,
|
|
34
|
+
"bash": true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"prReviewer": {
|
|
38
|
+
"enabled": true,
|
|
39
|
+
"model": "github-copilot/claude-haiku-4.5",
|
|
40
|
+
"mode": "subagent",
|
|
41
|
+
"tools": {
|
|
42
|
+
"write": false,
|
|
43
|
+
"edit": false,
|
|
44
|
+
"bash": false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"ralph": {
|
|
49
|
+
"enabled": true,
|
|
50
|
+
"defaultMaxIterations": 10,
|
|
51
|
+
"defaultTimeoutMs": 300000,
|
|
52
|
+
"parallelDefault": false,
|
|
53
|
+
"autoVerify": true,
|
|
54
|
+
"exportCheckpoints": true,
|
|
55
|
+
"validatePrd": true,
|
|
56
|
+
"detectEdgeCases": true
|
|
57
|
+
},
|
|
58
|
+
"plugins": {
|
|
59
|
+
"lintFormat": {
|
|
60
|
+
"enabled": true,
|
|
61
|
+
"runOnEdit": true,
|
|
62
|
+
"extensions": [".ts", ".tsx", ".js", ".jsx", ".vue", ".scss", ".css"],
|
|
63
|
+
"commands": {
|
|
64
|
+
"format": "npm run format",
|
|
65
|
+
"lint": "npm run lint"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"validateStandards": {
|
|
69
|
+
"enabled": true,
|
|
70
|
+
"strictMode": true,
|
|
71
|
+
"checkOnSave": true
|
|
72
|
+
},
|
|
73
|
+
"validateTypescript": {
|
|
74
|
+
"enabled": true,
|
|
75
|
+
"strictMode": true,
|
|
76
|
+
"checkOnSave": true
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"verification": {
|
|
80
|
+
"commands": {
|
|
81
|
+
"typeCheck": "npx tsc --noEmit",
|
|
82
|
+
"lint": "npm run lint",
|
|
83
|
+
"test": "npm test",
|
|
84
|
+
"build": "npm run build",
|
|
85
|
+
"all": "npm test && npm run lint && npx tsc --noEmit && npm run build"
|
|
86
|
+
},
|
|
87
|
+
"successPatterns": {
|
|
88
|
+
"typeCheck": "Found 0 errors",
|
|
89
|
+
"lint": "no problems",
|
|
90
|
+
"test": "All tests passed",
|
|
91
|
+
"build": "Build successful"
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"quality": {
|
|
95
|
+
"testCoverage": {
|
|
96
|
+
"enabled": true,
|
|
97
|
+
"minimum": 70,
|
|
98
|
+
"target": 80
|
|
99
|
+
},
|
|
100
|
+
"maxFileSize": {
|
|
101
|
+
"enabled": true,
|
|
102
|
+
"maxLines": 500,
|
|
103
|
+
"warningLines": 300
|
|
104
|
+
},
|
|
105
|
+
"complexity": {
|
|
106
|
+
"enabled": true,
|
|
107
|
+
"maxCyclomaticComplexity": 10
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"git": {
|
|
111
|
+
"autoCommit": false,
|
|
112
|
+
"commitMessageTemplate": "{{type}}({{scope}}): {{subject}}",
|
|
113
|
+
"branchNamingTemplate": "{{type}}/{{ticket}}-{{description}}",
|
|
114
|
+
"types": ["feat", "fix", "refactor", "docs", "test", "chore"]
|
|
115
|
+
},
|
|
116
|
+
"paths": {
|
|
117
|
+
"agents": ".opencode/agents",
|
|
118
|
+
"skills": ".opencode/skills",
|
|
119
|
+
"plugins": ".opencode/plugins",
|
|
120
|
+
"templates": ".opencode/templates",
|
|
121
|
+
"context": "context",
|
|
122
|
+
"output": "output"
|
|
123
|
+
},
|
|
124
|
+
"logging": {
|
|
125
|
+
"level": "info",
|
|
126
|
+
"file": ".opencode/opencode.log",
|
|
127
|
+
"console": true
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# Global Coding Standards
|
|
2
|
+
|
|
3
|
+
These rules apply to all code regardless of language or framework.
|
|
4
|
+
|
|
5
|
+
## Core Principles
|
|
6
|
+
|
|
7
|
+
### 1. Readability First
|
|
8
|
+
|
|
9
|
+
Code is read more than written. Optimize for the reader.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
// ❌ Clever but unclear
|
|
13
|
+
const result = arr.filter(Boolean).map(x => +x * 2);
|
|
14
|
+
|
|
15
|
+
// ✅ Clear and readable
|
|
16
|
+
const result = arr
|
|
17
|
+
.filter(item => item !== null && item !== undefined)
|
|
18
|
+
.map(item => Number(item) * 2);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 2. Single Responsibility
|
|
22
|
+
|
|
23
|
+
Each function/component should do one thing well.
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
// ❌ Does too much
|
|
27
|
+
function processOrder(order) {
|
|
28
|
+
validateOrder(order);
|
|
29
|
+
calculateTotal(order);
|
|
30
|
+
chargePayment(order);
|
|
31
|
+
sendEmail(order);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ✅ Single responsibility
|
|
35
|
+
function processOrder(order: Order): ProcessResult {
|
|
36
|
+
// Orchestration only
|
|
37
|
+
return pipe(validate, calculate, charge, notify)(order);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 3. Explicit Over Implicit
|
|
42
|
+
|
|
43
|
+
Be clear about what code does.
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
// ❌ Implicit behavior
|
|
47
|
+
function save(data) {
|
|
48
|
+
localStorage.setItem('data', JSON.stringify(data));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ✅ Explicit behavior
|
|
52
|
+
function saveToLocalStorage(key: string, data: unknown): void {
|
|
53
|
+
localStorage.setItem(key, JSON.stringify(data));
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 4. Fail Fast and Loud
|
|
58
|
+
|
|
59
|
+
Errors should be obvious, not silent.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
// ❌ Silent failure
|
|
63
|
+
function getConfig(key) {
|
|
64
|
+
return config[key];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ✅ Fail loud
|
|
68
|
+
function getConfig(key: keyof Config): ConfigValue {
|
|
69
|
+
const value = config[key];
|
|
70
|
+
if (value === undefined) {
|
|
71
|
+
throw new Error(`Missing config: ${key}`);
|
|
72
|
+
}
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 5. Consistency
|
|
78
|
+
|
|
79
|
+
Follow the same patterns throughout the codebase.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// Pick a style and stick with it
|
|
83
|
+
// ✅ Consistent naming
|
|
84
|
+
const userCount = users.length;
|
|
85
|
+
const itemCount = items.length;
|
|
86
|
+
const orderCount = orders.length;
|
|
87
|
+
|
|
88
|
+
// ❌ Inconsistent naming
|
|
89
|
+
const userCount = users.length;
|
|
90
|
+
const numItems = items.length;
|
|
91
|
+
const ordersLength = orders.length;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Naming Conventions
|
|
95
|
+
|
|
96
|
+
### Variables
|
|
97
|
+
|
|
98
|
+
- Use descriptive names: `userCount` not `n`
|
|
99
|
+
- Boolean names should read naturally: `isActive`, `hasPermission`
|
|
100
|
+
- Avoid negatives: `isDisabled` not `isNotEnabled`
|
|
101
|
+
|
|
102
|
+
### Functions
|
|
103
|
+
|
|
104
|
+
- Functions should describe actions: `getUser()`, `calculateTotal()`
|
|
105
|
+
- Boolean functions should be questions: `isValid()`, `canEdit()`
|
|
106
|
+
- Event handlers describe what happens: `handleSubmit()`, `handleClick()`
|
|
107
|
+
|
|
108
|
+
### Classes/Types
|
|
109
|
+
|
|
110
|
+
- Use PascalCase: `UserService`, `OrderStatus`
|
|
111
|
+
- Nouns, not verbs: `User` not `CreateUser`
|
|
112
|
+
|
|
113
|
+
### Constants
|
|
114
|
+
|
|
115
|
+
- SCREAMING_SNAKE_CASE for true constants: `MAX_RETRIES`, `API_BASE_URL`
|
|
116
|
+
- camelCase for configuration objects: `defaultConfig`, `themeSettings`
|
|
117
|
+
|
|
118
|
+
## File Organization
|
|
119
|
+
|
|
120
|
+
### Import Order
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// 1. External dependencies
|
|
124
|
+
import { useState } from 'react';
|
|
125
|
+
import { z } from 'zod';
|
|
126
|
+
|
|
127
|
+
// 2. Internal modules (using aliases)
|
|
128
|
+
import { Button } from '@/components/ui';
|
|
129
|
+
import { useAuth } from '@/hooks/useAuth';
|
|
130
|
+
|
|
131
|
+
// 3. Relative imports
|
|
132
|
+
import { helper } from './utils';
|
|
133
|
+
|
|
134
|
+
// 4. Types
|
|
135
|
+
import type { User } from '@/types';
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Export Order
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
// 1. Types
|
|
142
|
+
export type { User, UserCreateInput };
|
|
143
|
+
|
|
144
|
+
// 2. Constants
|
|
145
|
+
export const MAX_USERS = 100;
|
|
146
|
+
|
|
147
|
+
// 3. Functions/Classes
|
|
148
|
+
export function createUser() {}
|
|
149
|
+
export class UserService {}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Error Handling
|
|
153
|
+
|
|
154
|
+
### Use Specific Errors
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
// ❌ Generic
|
|
158
|
+
throw new Error('Something went wrong');
|
|
159
|
+
|
|
160
|
+
// ✅ Specific
|
|
161
|
+
throw new ValidationError('Email is invalid', { field: 'email' });
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Handle at Boundaries
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
// ❌ Silent catch
|
|
168
|
+
try {
|
|
169
|
+
doSomething();
|
|
170
|
+
} catch (e) {}
|
|
171
|
+
|
|
172
|
+
// ✅ Proper handling
|
|
173
|
+
try {
|
|
174
|
+
doSomething();
|
|
175
|
+
} catch (error) {
|
|
176
|
+
logger.error('Operation failed', { error });
|
|
177
|
+
throw new ServiceError('Operation failed', { cause: error });
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Comments
|
|
182
|
+
|
|
183
|
+
### When to Comment
|
|
184
|
+
|
|
185
|
+
- Explain WHY, not WHAT
|
|
186
|
+
- Document complex algorithms
|
|
187
|
+
- Add TODOs with context and issue links
|
|
188
|
+
- Document public APIs
|
|
189
|
+
|
|
190
|
+
### When NOT to Comment
|
|
191
|
+
|
|
192
|
+
- Don't explain obvious code
|
|
193
|
+
- Don't leave commented-out code
|
|
194
|
+
- Don't write comments that can become outdated
|
|
195
|
+
|
|
196
|
+
## Testing Standards
|
|
197
|
+
|
|
198
|
+
### Test Names
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
// ❌ Vague
|
|
202
|
+
test('user', () => {});
|
|
203
|
+
|
|
204
|
+
// ✅ Descriptive
|
|
205
|
+
test('should create user with valid email', () => {});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Test Structure
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
describe('UserService', () => {
|
|
212
|
+
describe('createUser', () => {
|
|
213
|
+
it('should create user with valid data', () => {
|
|
214
|
+
// Arrange
|
|
215
|
+
const input = { email: 'test@example.com' };
|
|
216
|
+
|
|
217
|
+
// Act
|
|
218
|
+
const result = userService.createUser(input);
|
|
219
|
+
|
|
220
|
+
// Assert
|
|
221
|
+
expect(result.email).toBe(input.email);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Git Conventions
|
|
228
|
+
|
|
229
|
+
### Commit Messages
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
type(scope): description
|
|
233
|
+
|
|
234
|
+
[optional body]
|
|
235
|
+
|
|
236
|
+
[optional footer]
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Types: `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore`
|
|
240
|
+
|
|
241
|
+
### Branch Names
|
|
242
|
+
|
|
243
|
+
- `feature/description` - New features
|
|
244
|
+
- `fix/description` - Bug fixes
|
|
245
|
+
- `refactor/description` - Code improvements
|
|
246
|
+
- `docs/description` - Documentation
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
**These standards ensure code quality and maintainability.**
|