ccjk 14.1.10 → 14.2.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/dist/chunks/agent-teams.mjs +1 -1
- package/dist/chunks/api-cli.mjs +1 -1
- package/dist/chunks/api-config-selector.mjs +3 -3
- package/dist/chunks/ccjk-all.mjs +1 -1
- package/dist/chunks/ccjk-mcp.mjs +1 -1
- package/dist/chunks/ccjk-setup.mjs +1 -1
- package/dist/chunks/ccr.mjs +8 -8
- package/dist/chunks/check-updates.mjs +1 -1
- package/dist/chunks/claude-code-incremental-manager.mjs +3 -3
- package/dist/chunks/claude-config.mjs +1 -1
- package/dist/chunks/codex-config-switch.mjs +1 -1
- package/dist/chunks/codex-provider-manager.mjs +1 -1
- package/dist/chunks/config-switch.mjs +1 -1
- package/dist/chunks/config.mjs +19 -3
- package/dist/chunks/config2.mjs +1 -1
- package/dist/chunks/config3.mjs +1 -1
- package/dist/chunks/doctor.mjs +175 -6
- package/dist/chunks/features.mjs +3 -3
- package/dist/chunks/index10.mjs +19 -5
- package/dist/chunks/init.mjs +5 -5
- package/dist/chunks/mcp-cli.mjs +3 -3
- package/dist/chunks/mcp.mjs +3 -3
- package/dist/chunks/package.mjs +1 -1
- package/dist/chunks/quick-provider.mjs +1 -1
- package/dist/chunks/quick-setup.mjs +5 -5
- package/dist/chunks/simple-config.mjs +1 -1
- package/dist/chunks/smart-guide.mjs +1 -1
- package/dist/chunks/update.mjs +6 -6
- package/dist/chunks/zero-config.mjs +7 -4
- package/dist/cli.mjs +0 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +1 -1
- package/dist/shared/{ccjk.BJ3Zpjo5.mjs → ccjk.BCzOWT1L.mjs} +3 -2
- package/dist/shared/{ccjk.B8oqkakg.mjs → ccjk.BLsIiTqO.mjs} +1 -1
- package/dist/shared/{ccjk.Hwoicrh8.mjs → ccjk.BXv8aYs1.mjs} +1 -1
- package/dist/shared/{ccjk.B9OuS4xZ.mjs → ccjk.CfKJnpbB.mjs} +1 -1
- package/dist/shared/{ccjk.BzxpiEPF.mjs → ccjk.Cgv_cFVX.mjs} +2 -2
- package/dist/shared/{ccjk.Di1IYU3u.mjs → ccjk.DDL-4C-k.mjs} +47 -10
- package/dist/shared/{ccjk.BEiR3L4C.mjs → ccjk.DOw7Fawt.mjs} +3 -3
- package/dist/shared/{ccjk.tI_s2uSh.mjs → ccjk.f3TBLJSt.mjs} +1 -1
- package/dist/templates/agents/README.md +78 -0
- package/dist/templates/common/error-prevention.md +267 -0
- package/dist/templates/common/karpathy-baseline.md +83 -0
- package/dist/templates/common/output-styles/zh-CN/carmack-mode.md +381 -0
- package/dist/templates/common/output-styles/zh-CN/dhh-mode.md +265 -0
- package/dist/templates/common/output-styles/zh-CN/evan-you-mode.md +539 -0
- package/dist/templates/common/output-styles/zh-CN/jobs-mode.md +369 -0
- package/dist/templates/common/output-styles/zh-CN/linus-mode.md +135 -0
- package/dist/templates/common/output-styles/zh-CN/uncle-bob-mode.md +221 -0
- package/dist/templates/common/workflow/continuousDelivery/en/continuous-delivery.md +628 -0
- package/dist/templates/common/workflow/continuousDelivery/zh-CN/continuous-delivery.md +628 -0
- package/dist/templates/common/workflow/essential/en/agents/ccjk-config-agent.md +187 -0
- package/dist/templates/common/workflow/essential/en/agents/ccjk-mcp-agent.md +191 -0
- package/dist/templates/common/workflow/essential/en/agents/ccjk-skill-agent.md +249 -0
- package/dist/templates/common/workflow/essential/en/agents/ccjk-workflow-agent.md +277 -0
- package/dist/templates/common/workflow/essential/en/agents/get-current-datetime.md +29 -0
- package/dist/templates/common/workflow/essential/en/agents/init-architect.md +115 -0
- package/dist/templates/common/workflow/essential/en/agents/ui-ux-designer.md +91 -0
- package/dist/templates/common/workflow/essential/en/feat.md +92 -0
- package/dist/templates/common/workflow/essential/en/goal.md +147 -0
- package/dist/templates/common/workflow/essential/en/init-project.md +53 -0
- package/dist/templates/common/workflow/essential/zh-CN/agents/get-current-datetime.md +29 -0
- package/dist/templates/common/workflow/essential/zh-CN/agents/init-architect.md +115 -0
- package/dist/templates/common/workflow/essential/zh-CN/agents/ui-ux-designer.md +91 -0
- package/dist/templates/common/workflow/essential/zh-CN/feat.md +315 -0
- package/dist/templates/common/workflow/essential/zh-CN/goal.md +146 -0
- package/dist/templates/common/workflow/essential/zh-CN/init-project.md +53 -0
- package/dist/templates/common/workflow/git/en/git-cleanBranches.md +102 -0
- package/dist/templates/common/workflow/git/en/git-commit.md +205 -0
- package/dist/templates/common/workflow/git/en/git-rollback.md +90 -0
- package/dist/templates/common/workflow/git/en/git-worktree.md +276 -0
- package/dist/templates/common/workflow/git/zh-CN/git-cleanBranches.md +102 -0
- package/dist/templates/common/workflow/git/zh-CN/git-commit.md +205 -0
- package/dist/templates/common/workflow/git/zh-CN/git-rollback.md +90 -0
- package/dist/templates/common/workflow/git/zh-CN/git-worktree.md +276 -0
- package/dist/templates/common/workflow/interview/en/interview.md +67 -0
- package/dist/templates/common/workflow/interview/zh-CN/interview.md +67 -0
- package/dist/templates/common/workflow/linearMethod/en/linear-method.md +651 -0
- package/dist/templates/common/workflow/linearMethod/zh-CN/linear-method.md +752 -0
- package/dist/templates/common/workflow/refactoringMaster/en/refactoring-master.md +516 -0
- package/dist/templates/common/workflow/refactoringMaster/zh-CN/refactoring-master.md +812 -0
- package/dist/templates/common/workflow/sixStep/en/workflow.md +83 -0
- package/dist/templates/common/workflow/sixStep/zh-CN/workflow.md +359 -0
- package/dist/templates/common/workflow/specFirstTDD/en/spec-first-tdd.md +364 -0
- package/dist/templates/common/workflow/specFirstTDD/zh-CN/spec-first-tdd.md +366 -0
- package/dist/templates/hooks/README.md +212 -0
- package/dist/templates/hooks/git-workflow-hooks.md +551 -0
- package/dist/templates/hooks/post-test-coverage.md +434 -0
- package/dist/templates/hooks/pre-commit-black.md +274 -0
- package/dist/templates/hooks/pre-commit-eslint.md +153 -0
- package/dist/templates/hooks/pre-commit-gofmt.md +284 -0
- package/dist/templates/hooks/pre-commit-prettier.md +212 -0
- package/dist/templates/hooks/pre-commit-type-check.md +377 -0
- package/dist/templates/skills/ccjk-init.md +154 -0
- package/dist/templates/skills/ccjk-mcp-setup.md +205 -0
- package/dist/templates/skills/ccjk-troubleshoot.md +228 -0
- package/dist/templates/skills/django-patterns.md +1016 -0
- package/dist/templates/skills/git-workflow.md +748 -0
- package/dist/templates/skills/go-idioms.md +963 -0
- package/dist/templates/skills/nextjs-optimization.md +694 -0
- package/dist/templates/skills/python-pep8.md +852 -0
- package/dist/templates/skills/react-patterns.md +686 -0
- package/dist/templates/skills/rust-patterns.md +1057 -0
- package/dist/templates/skills/security-best-practices.md +1413 -0
- package/dist/templates/skills/testing-best-practices.md +1315 -0
- package/dist/templates/skills/ts-best-practices.md +354 -0
- package/package.json +40 -43
- package/templates/common/karpathy-baseline.md +83 -0
- package/templates/common/output-styles/zh-CN/carmack-mode.md +14 -0
- package/templates/common/output-styles/zh-CN/dhh-mode.md +14 -0
- package/templates/common/output-styles/zh-CN/evan-you-mode.md +14 -0
- package/templates/common/output-styles/zh-CN/jobs-mode.md +14 -0
- package/templates/common/output-styles/zh-CN/linus-mode.md +14 -0
- package/templates/common/output-styles/zh-CN/uncle-bob-mode.md +14 -0
- package/templates/common/workflow/linearMethod/zh-CN/linear-method.md +2 -0
- package/templates/common/workflow/refactoringMaster/zh-CN/refactoring-master.md +2 -0
- package/templates/common/workflow/sixStep/zh-CN/workflow.md +2 -0
- package/templates/common/workflow/specFirstTDD/zh-CN/spec-first-tdd.md +2 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: post-test-coverage
|
|
3
|
+
type: PostToolUse
|
|
4
|
+
name: Test Coverage Post-test Hook
|
|
5
|
+
description: Generate test coverage reports after running tests
|
|
6
|
+
priority: 5
|
|
7
|
+
matcher: Bash(*test*)
|
|
8
|
+
command: npx vitest --coverage
|
|
9
|
+
timeout: 60000
|
|
10
|
+
enabled: true
|
|
11
|
+
applicableTo: [all]
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# Test Coverage Post-test Hook
|
|
15
|
+
|
|
16
|
+
## Description
|
|
17
|
+
|
|
18
|
+
This hook automatically generates test coverage reports after running any test command. It helps maintain code quality by providing visibility into test coverage metrics and identifying untested code paths.
|
|
19
|
+
|
|
20
|
+
## 描述
|
|
21
|
+
|
|
22
|
+
此钩子在运行任何测试命令后自动生成测试覆盖率报告。它通过提供测试覆盖率指标的可见性和识别未测试的代码路径来帮助维护代码质量。
|
|
23
|
+
|
|
24
|
+
## When it runs
|
|
25
|
+
|
|
26
|
+
- **Trigger**: After any command containing "test" (e.g., `npm test`, `yarn test`, `vitest`, `jest`)
|
|
27
|
+
- **Condition**: When test configuration is detected (vitest.config.js, jest.config.js, etc.)
|
|
28
|
+
- **Scope**: Generates coverage for all tested files
|
|
29
|
+
|
|
30
|
+
## 运行时机
|
|
31
|
+
|
|
32
|
+
- **触发器**: 任何包含 "test" 的命令之后(例如 `npm test`、`yarn test`、`vitest`、`jest`)
|
|
33
|
+
- **条件**: 检测到测试配置时(vitest.config.js、jest.config.js 等)
|
|
34
|
+
- **范围**: 为所有测试文件生成覆盖率
|
|
35
|
+
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
### Prerequisites for Vitest
|
|
39
|
+
```bash
|
|
40
|
+
# Install Vitest with coverage support
|
|
41
|
+
npm install --save-dev vitest @vitest/ui c8
|
|
42
|
+
|
|
43
|
+
# Or with specific coverage provider
|
|
44
|
+
npm install --save-dev vitest @vitest/coverage-v8
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Prerequisites for Jest
|
|
48
|
+
```bash
|
|
49
|
+
# Install Jest with coverage support
|
|
50
|
+
npm install --save-dev jest @types/jest
|
|
51
|
+
|
|
52
|
+
# Or with additional coverage tools
|
|
53
|
+
npm install --save-dev jest babel-jest @babel/preset-env
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Vitest Configuration
|
|
57
|
+
```javascript
|
|
58
|
+
// vitest.config.js
|
|
59
|
+
import { defineConfig } from 'vitest/config'
|
|
60
|
+
|
|
61
|
+
export default defineConfig({
|
|
62
|
+
test: {
|
|
63
|
+
coverage: {
|
|
64
|
+
provider: 'v8', // or 'c8'
|
|
65
|
+
reporter: ['text', 'json', 'html'],
|
|
66
|
+
reportsDirectory: './coverage',
|
|
67
|
+
exclude: [
|
|
68
|
+
'node_modules/',
|
|
69
|
+
'dist/',
|
|
70
|
+
'**/*.d.ts',
|
|
71
|
+
'**/*.config.js',
|
|
72
|
+
'**/test/**',
|
|
73
|
+
'**/*.test.{js,ts,jsx,tsx}'
|
|
74
|
+
],
|
|
75
|
+
thresholds: {
|
|
76
|
+
global: {
|
|
77
|
+
branches: 80,
|
|
78
|
+
functions: 80,
|
|
79
|
+
lines: 80,
|
|
80
|
+
statements: 80
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Jest Configuration
|
|
89
|
+
```json
|
|
90
|
+
// package.json
|
|
91
|
+
{
|
|
92
|
+
"jest": {
|
|
93
|
+
"collectCoverage": true,
|
|
94
|
+
"coverageDirectory": "coverage",
|
|
95
|
+
"coverageReporters": ["text", "lcov", "html"],
|
|
96
|
+
"coverageThreshold": {
|
|
97
|
+
"global": {
|
|
98
|
+
"branches": 80,
|
|
99
|
+
"functions": 80,
|
|
100
|
+
"lines": 80,
|
|
101
|
+
"statements": 80
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"collectCoverageFrom": [
|
|
105
|
+
"src/**/*.{js,ts,jsx,tsx}",
|
|
106
|
+
"!src/**/*.d.ts",
|
|
107
|
+
"!src/**/*.test.{js,ts,jsx,tsx}"
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Hook Configuration
|
|
114
|
+
```yaml
|
|
115
|
+
# In your CCJK configuration
|
|
116
|
+
hooks:
|
|
117
|
+
post-test-coverage:
|
|
118
|
+
enabled: true
|
|
119
|
+
command: "npx vitest --coverage"
|
|
120
|
+
timeout: 60000
|
|
121
|
+
generateReport: true
|
|
122
|
+
openReport: false
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## 配置
|
|
126
|
+
|
|
127
|
+
### Vitest 前置条件
|
|
128
|
+
```bash
|
|
129
|
+
# 安装支持覆盖率的 Vitest
|
|
130
|
+
npm install --save-dev vitest @vitest/ui c8
|
|
131
|
+
|
|
132
|
+
# 或使用特定的覆盖率提供程序
|
|
133
|
+
npm install --save-dev vitest @vitest/coverage-v8
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Jest 前置条件
|
|
137
|
+
```bash
|
|
138
|
+
# 安装支持覆盖率的 Jest
|
|
139
|
+
npm install --save-dev jest @types/jest
|
|
140
|
+
|
|
141
|
+
# 或使用额外的覆盖率工具
|
|
142
|
+
npm install --save-dev jest babel-jest @babel/preset-env
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Customization
|
|
146
|
+
|
|
147
|
+
### Different Coverage Providers
|
|
148
|
+
```yaml
|
|
149
|
+
# For Vitest with v8
|
|
150
|
+
hooks:
|
|
151
|
+
post-test-coverage:
|
|
152
|
+
command: "npx vitest --coverage --coverage.provider=v8"
|
|
153
|
+
|
|
154
|
+
# For Vitest with c8
|
|
155
|
+
hooks:
|
|
156
|
+
post-test-coverage:
|
|
157
|
+
command: "npx vitest --coverage --coverage.provider=c8"
|
|
158
|
+
|
|
159
|
+
# For Jest
|
|
160
|
+
hooks:
|
|
161
|
+
post-test-coverage:
|
|
162
|
+
command: "npx jest --coverage"
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Custom Coverage Thresholds
|
|
166
|
+
```yaml
|
|
167
|
+
hooks:
|
|
168
|
+
post-test-coverage:
|
|
169
|
+
command: "npx vitest --coverage --coverage.thresholds.lines=90 --coverage.thresholds.functions=90"
|
|
170
|
+
failOnThreshold: true
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Multiple Test Frameworks
|
|
174
|
+
```yaml
|
|
175
|
+
hooks:
|
|
176
|
+
post-test-coverage-unit:
|
|
177
|
+
matcher: "Bash(*unit*test*)"
|
|
178
|
+
command: "npx vitest --coverage --config vitest.unit.config.js"
|
|
179
|
+
priority: 5
|
|
180
|
+
post-test-coverage-integration:
|
|
181
|
+
matcher: "Bash(*integration*test*)"
|
|
182
|
+
command: "npx jest --coverage --config jest.integration.config.js"
|
|
183
|
+
priority: 5
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Coverage Report Formats
|
|
187
|
+
```yaml
|
|
188
|
+
hooks:
|
|
189
|
+
post-test-coverage:
|
|
190
|
+
command: "npx vitest --coverage --coverage.reporter=text --coverage.reporter=html --coverage.reporter=json"
|
|
191
|
+
artifacts: ["coverage/index.html", "coverage/coverage-final.json"]
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Conditional Coverage Generation
|
|
195
|
+
```yaml
|
|
196
|
+
hooks:
|
|
197
|
+
post-test-coverage:
|
|
198
|
+
command: |
|
|
199
|
+
if [ "$CI" = "true" ]; then
|
|
200
|
+
npx vitest --coverage --coverage.reporter=lcov
|
|
201
|
+
else
|
|
202
|
+
npx vitest --coverage --coverage.reporter=html
|
|
203
|
+
fi
|
|
204
|
+
description: "Generate different coverage formats for CI vs local"
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## 自定义
|
|
208
|
+
|
|
209
|
+
### 不同的覆盖率提供程序
|
|
210
|
+
```yaml
|
|
211
|
+
# 使用 v8 的 Vitest
|
|
212
|
+
hooks:
|
|
213
|
+
post-test-coverage:
|
|
214
|
+
command: "npx vitest --coverage --coverage.provider=v8"
|
|
215
|
+
|
|
216
|
+
# 使用 c8 的 Vitest
|
|
217
|
+
hooks:
|
|
218
|
+
post-test-coverage:
|
|
219
|
+
command: "npx vitest --coverage --coverage.provider=c8"
|
|
220
|
+
|
|
221
|
+
# Jest
|
|
222
|
+
hooks:
|
|
223
|
+
post-test-coverage:
|
|
224
|
+
command: "npx jest --coverage"
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### 自定义覆盖率阈值
|
|
228
|
+
```yaml
|
|
229
|
+
hooks:
|
|
230
|
+
post-test-coverage:
|
|
231
|
+
command: "npx vitest --coverage --coverage.thresholds.lines=90 --coverage.thresholds.functions=90"
|
|
232
|
+
failOnThreshold: true
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Error Handling
|
|
236
|
+
|
|
237
|
+
- **Coverage below threshold**: Hook fails with detailed coverage report
|
|
238
|
+
- **No tests found**: Hook is skipped with informational message
|
|
239
|
+
- **Coverage tool missing**: Hook is skipped with installation instructions
|
|
240
|
+
- **Timeout**: Hook fails after 60 seconds (configurable)
|
|
241
|
+
- **Report generation failure**: Hook continues but logs warning
|
|
242
|
+
|
|
243
|
+
## 错误处理
|
|
244
|
+
|
|
245
|
+
- **覆盖率低于阈值**: 钩子失败并显示详细的覆盖率报告
|
|
246
|
+
- **未找到测试**: 跳过钩子并显示信息消息
|
|
247
|
+
- **缺少覆盖率工具**: 跳过钩子并显示安装说明
|
|
248
|
+
- **超时**: 60 秒后钩子失败(可配置)
|
|
249
|
+
- **报告生成失败**: 钩子继续但记录警告
|
|
250
|
+
|
|
251
|
+
## Advanced Configuration
|
|
252
|
+
|
|
253
|
+
### Coverage Exclusions
|
|
254
|
+
```javascript
|
|
255
|
+
// vitest.config.js
|
|
256
|
+
export default defineConfig({
|
|
257
|
+
test: {
|
|
258
|
+
coverage: {
|
|
259
|
+
exclude: [
|
|
260
|
+
'node_modules/',
|
|
261
|
+
'dist/',
|
|
262
|
+
'build/',
|
|
263
|
+
'coverage/',
|
|
264
|
+
'**/*.d.ts',
|
|
265
|
+
'**/*.config.{js,ts}',
|
|
266
|
+
'**/*.test.{js,ts,jsx,tsx}',
|
|
267
|
+
'**/*.spec.{js,ts,jsx,tsx}',
|
|
268
|
+
'**/test/**',
|
|
269
|
+
'**/tests/**',
|
|
270
|
+
'**/__tests__/**',
|
|
271
|
+
'**/__mocks__/**',
|
|
272
|
+
'**/vendor/**',
|
|
273
|
+
'**/generated/**'
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
})
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Branch-specific Coverage
|
|
281
|
+
```yaml
|
|
282
|
+
hooks:
|
|
283
|
+
post-test-coverage-main:
|
|
284
|
+
matcher: "Bash(*test*)"
|
|
285
|
+
command: |
|
|
286
|
+
if [ "$(git branch --show-current)" = "main" ]; then
|
|
287
|
+
npx vitest --coverage --coverage.thresholds.lines=95
|
|
288
|
+
else
|
|
289
|
+
npx vitest --coverage --coverage.thresholds.lines=80
|
|
290
|
+
fi
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Coverage Badges Generation
|
|
294
|
+
```yaml
|
|
295
|
+
hooks:
|
|
296
|
+
post-test-coverage:
|
|
297
|
+
command: |
|
|
298
|
+
npx vitest --coverage
|
|
299
|
+
npx coverage-badges-cli --output ./badges/coverage.svg
|
|
300
|
+
artifacts: ["badges/coverage.svg"]
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Integration with SonarQube
|
|
304
|
+
```yaml
|
|
305
|
+
hooks:
|
|
306
|
+
post-test-coverage:
|
|
307
|
+
command: |
|
|
308
|
+
npx vitest --coverage --coverage.reporter=lcov
|
|
309
|
+
sonar-scanner -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## 高级配置
|
|
313
|
+
|
|
314
|
+
### 覆盖率排除
|
|
315
|
+
```javascript
|
|
316
|
+
// vitest.config.js
|
|
317
|
+
export default defineConfig({
|
|
318
|
+
test: {
|
|
319
|
+
coverage: {
|
|
320
|
+
exclude: [
|
|
321
|
+
'node_modules/',
|
|
322
|
+
'dist/',
|
|
323
|
+
'build/',
|
|
324
|
+
'coverage/',
|
|
325
|
+
'**/*.d.ts',
|
|
326
|
+
'**/*.config.{js,ts}',
|
|
327
|
+
'**/*.test.{js,ts,jsx,tsx}',
|
|
328
|
+
'**/*.spec.{js,ts,jsx,tsx}',
|
|
329
|
+
'**/test/**',
|
|
330
|
+
'**/tests/**',
|
|
331
|
+
'**/__tests__/**',
|
|
332
|
+
'**/__mocks__/**',
|
|
333
|
+
'**/vendor/**',
|
|
334
|
+
'**/generated/**'
|
|
335
|
+
]
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
})
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### 分支特定覆盖率
|
|
342
|
+
```yaml
|
|
343
|
+
hooks:
|
|
344
|
+
post-test-coverage-main:
|
|
345
|
+
matcher: "Bash(*test*)"
|
|
346
|
+
command: |
|
|
347
|
+
if [ "$(git branch --show-current)" = "main" ]; then
|
|
348
|
+
npx vitest --coverage --coverage.thresholds.lines=95
|
|
349
|
+
else
|
|
350
|
+
npx vitest --coverage --coverage.thresholds.lines=80
|
|
351
|
+
fi
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
## Performance Tips
|
|
355
|
+
|
|
356
|
+
### Incremental Coverage
|
|
357
|
+
```javascript
|
|
358
|
+
// vitest.config.js
|
|
359
|
+
export default defineConfig({
|
|
360
|
+
test: {
|
|
361
|
+
coverage: {
|
|
362
|
+
skipFull: true, // Skip files with 100% coverage
|
|
363
|
+
clean: false, // Don't clean coverage directory
|
|
364
|
+
cleanOnRerun: false
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
})
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Parallel Coverage Generation
|
|
371
|
+
```yaml
|
|
372
|
+
hooks:
|
|
373
|
+
post-test-coverage:
|
|
374
|
+
command: "npx vitest --coverage --reporter=verbose --threads"
|
|
375
|
+
parallel: true
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
## 性能提示
|
|
379
|
+
|
|
380
|
+
### 增量覆盖率
|
|
381
|
+
```javascript
|
|
382
|
+
// vitest.config.js
|
|
383
|
+
export default defineConfig({
|
|
384
|
+
test: {
|
|
385
|
+
coverage: {
|
|
386
|
+
skipFull: true, // 跳过 100% 覆盖率的文件
|
|
387
|
+
clean: false, // 不清理覆盖率目录
|
|
388
|
+
cleanOnRerun: false
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
})
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## Integration with CI/CD
|
|
395
|
+
|
|
396
|
+
### GitHub Actions
|
|
397
|
+
```yaml
|
|
398
|
+
# .github/workflows/test.yml
|
|
399
|
+
- name: Run tests with coverage
|
|
400
|
+
run: npm test
|
|
401
|
+
|
|
402
|
+
- name: Upload coverage to Codecov
|
|
403
|
+
uses: codecov/codecov-action@v3
|
|
404
|
+
with:
|
|
405
|
+
file: ./coverage/lcov.info
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
### GitLab CI
|
|
409
|
+
```yaml
|
|
410
|
+
# .gitlab-ci.yml
|
|
411
|
+
test:
|
|
412
|
+
script:
|
|
413
|
+
- npm test
|
|
414
|
+
coverage: '/Lines\s*:\s*(\d+\.\d+)%/'
|
|
415
|
+
artifacts:
|
|
416
|
+
reports:
|
|
417
|
+
coverage_report:
|
|
418
|
+
coverage_format: cobertura
|
|
419
|
+
path: coverage/cobertura-coverage.xml
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
## 与 CI/CD 集成
|
|
423
|
+
|
|
424
|
+
### GitHub Actions
|
|
425
|
+
```yaml
|
|
426
|
+
# .github/workflows/test.yml
|
|
427
|
+
- name: 运行带覆盖率的测试
|
|
428
|
+
run: npm test
|
|
429
|
+
|
|
430
|
+
- name: 上传覆盖率到 Codecov
|
|
431
|
+
uses: codecov/codecov-action@v3
|
|
432
|
+
with:
|
|
433
|
+
file: ./coverage/lcov.info
|
|
434
|
+
```
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: pre-commit-black
|
|
3
|
+
type: PreToolUse
|
|
4
|
+
name: Black Pre-commit Hook
|
|
5
|
+
description: Automatically format Python code with Black before git commits
|
|
6
|
+
priority: 10
|
|
7
|
+
matcher: Bash(git commit *)
|
|
8
|
+
command: black .
|
|
9
|
+
timeout: 30000
|
|
10
|
+
enabled: true
|
|
11
|
+
applicableTo: [python, django, flask, fastapi]
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# Black Pre-commit Hook
|
|
15
|
+
|
|
16
|
+
## Description
|
|
17
|
+
|
|
18
|
+
This hook automatically runs Black, the uncompromising Python code formatter, before every git commit. Black ensures consistent Python code formatting with minimal configuration required.
|
|
19
|
+
|
|
20
|
+
## 描述
|
|
21
|
+
|
|
22
|
+
此钩子在每次 git 提交前自动运行 Black(不妥协的 Python 代码格式化工具)。Black 确保 Python 代码格式一致,且需要的配置最少。
|
|
23
|
+
|
|
24
|
+
## When it runs
|
|
25
|
+
|
|
26
|
+
- **Trigger**: Before any `git commit` command
|
|
27
|
+
- **Condition**: When Python files (`.py`) are detected in the project
|
|
28
|
+
- **Scope**: Runs on all Python files in the project
|
|
29
|
+
|
|
30
|
+
## 运行时机
|
|
31
|
+
|
|
32
|
+
- **触发器**: 任何 `git commit` 命令之前
|
|
33
|
+
- **条件**: 在项目中检测到 Python 文件(`.py`)时
|
|
34
|
+
- **范围**: 在项目中所有 Python 文件上运行
|
|
35
|
+
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
### Prerequisites
|
|
39
|
+
```bash
|
|
40
|
+
# Install Black
|
|
41
|
+
pip install black
|
|
42
|
+
|
|
43
|
+
# Or with development dependencies
|
|
44
|
+
pip install --dev black
|
|
45
|
+
|
|
46
|
+
# Or using poetry
|
|
47
|
+
poetry add --group dev black
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Basic Black Configuration
|
|
51
|
+
```toml
|
|
52
|
+
# pyproject.toml
|
|
53
|
+
[tool.black]
|
|
54
|
+
line-length = 88
|
|
55
|
+
target-version = ['py38', 'py39', 'py310', 'py311']
|
|
56
|
+
include = '\.pyi?$'
|
|
57
|
+
extend-exclude = '''
|
|
58
|
+
/(
|
|
59
|
+
# directories
|
|
60
|
+
\.eggs
|
|
61
|
+
| \.git
|
|
62
|
+
| \.hg
|
|
63
|
+
| \.mypy_cache
|
|
64
|
+
| \.tox
|
|
65
|
+
| \.venv
|
|
66
|
+
| build
|
|
67
|
+
| dist
|
|
68
|
+
)/
|
|
69
|
+
'''
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Hook Configuration
|
|
73
|
+
```yaml
|
|
74
|
+
# In your CCJK configuration
|
|
75
|
+
hooks:
|
|
76
|
+
pre-commit-black:
|
|
77
|
+
enabled: true
|
|
78
|
+
command: "black ."
|
|
79
|
+
timeout: 30000
|
|
80
|
+
checkFormatted: false
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 配置
|
|
84
|
+
|
|
85
|
+
### 前置条件
|
|
86
|
+
```bash
|
|
87
|
+
# 安装 Black
|
|
88
|
+
pip install black
|
|
89
|
+
|
|
90
|
+
# 或作为开发依赖
|
|
91
|
+
pip install --dev black
|
|
92
|
+
|
|
93
|
+
# 或使用 poetry
|
|
94
|
+
poetry add --group dev black
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 基本 Black 配置
|
|
98
|
+
```toml
|
|
99
|
+
# pyproject.toml
|
|
100
|
+
[tool.black]
|
|
101
|
+
line-length = 88
|
|
102
|
+
target-version = ['py38', 'py39', 'py310', 'py311']
|
|
103
|
+
include = '\.pyi?$'
|
|
104
|
+
extend-exclude = '''
|
|
105
|
+
/(
|
|
106
|
+
# directories
|
|
107
|
+
\.eggs
|
|
108
|
+
| \.git
|
|
109
|
+
| \.hg
|
|
110
|
+
| \.mypy_cache
|
|
111
|
+
| \.tox
|
|
112
|
+
| \.venv
|
|
113
|
+
| build
|
|
114
|
+
| dist
|
|
115
|
+
)/
|
|
116
|
+
'''
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Customization
|
|
120
|
+
|
|
121
|
+
### Custom Line Length
|
|
122
|
+
```toml
|
|
123
|
+
# pyproject.toml
|
|
124
|
+
[tool.black]
|
|
125
|
+
line-length = 100
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
```yaml
|
|
129
|
+
hooks:
|
|
130
|
+
pre-commit-black:
|
|
131
|
+
command: "black --line-length 100 ."
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Format Specific Directories Only
|
|
135
|
+
```yaml
|
|
136
|
+
hooks:
|
|
137
|
+
pre-commit-black:
|
|
138
|
+
command: "black src/ tests/"
|
|
139
|
+
include: ["src/**/*.py", "tests/**/*.py"]
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Check Mode (Don't Write)
|
|
143
|
+
```yaml
|
|
144
|
+
hooks:
|
|
145
|
+
pre-commit-black:
|
|
146
|
+
command: "black --check --diff ."
|
|
147
|
+
failOnUnformatted: true
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Skip String Normalization
|
|
151
|
+
```toml
|
|
152
|
+
# pyproject.toml
|
|
153
|
+
[tool.black]
|
|
154
|
+
skip-string-normalization = true
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
```yaml
|
|
158
|
+
hooks:
|
|
159
|
+
pre-commit-black:
|
|
160
|
+
command: "black --skip-string-normalization ."
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Integration with isort
|
|
164
|
+
```yaml
|
|
165
|
+
hooks:
|
|
166
|
+
pre-commit-isort:
|
|
167
|
+
command: "isort ."
|
|
168
|
+
priority: 11
|
|
169
|
+
pre-commit-black:
|
|
170
|
+
command: "black ."
|
|
171
|
+
priority: 10
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## 自定义
|
|
175
|
+
|
|
176
|
+
### 自定义行长度
|
|
177
|
+
```toml
|
|
178
|
+
# pyproject.toml
|
|
179
|
+
[tool.black]
|
|
180
|
+
line-length = 100
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### 仅格式化特定目录
|
|
184
|
+
```yaml
|
|
185
|
+
hooks:
|
|
186
|
+
pre-commit-black:
|
|
187
|
+
command: "black src/ tests/"
|
|
188
|
+
include: ["src/**/*.py", "tests/**/*.py"]
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### 检查模式(不写入)
|
|
192
|
+
```yaml
|
|
193
|
+
hooks:
|
|
194
|
+
pre-commit-black:
|
|
195
|
+
command: "black --check --diff ."
|
|
196
|
+
failOnUnformatted: true
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Error Handling
|
|
200
|
+
|
|
201
|
+
- **Formatting applied**: Python files are automatically formatted and commit continues
|
|
202
|
+
- **Syntax errors**: Commit is blocked with Python syntax error details
|
|
203
|
+
- **Timeout**: Hook fails after 30 seconds
|
|
204
|
+
- **Missing Black**: Hook is skipped with installation instructions
|
|
205
|
+
- **Permission errors**: Hook fails with file access error details
|
|
206
|
+
|
|
207
|
+
## 错误处理
|
|
208
|
+
|
|
209
|
+
- **应用格式化**: Python 文件自动格式化并继续提交
|
|
210
|
+
- **语法错误**: 阻止提交并显示 Python 语法错误详情
|
|
211
|
+
- **超时**: 30 秒后钩子失败
|
|
212
|
+
- **缺少 Black**: 跳过钩子并显示安装说明
|
|
213
|
+
- **权限错误**: 钩子失败并显示文件访问错误详情
|
|
214
|
+
|
|
215
|
+
## Advanced Configuration
|
|
216
|
+
|
|
217
|
+
### Jupyter Notebook Support
|
|
218
|
+
```yaml
|
|
219
|
+
hooks:
|
|
220
|
+
pre-commit-black:
|
|
221
|
+
command: "black --include '\.pyi?$|\.ipynb$' ."
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Multiple Python Versions
|
|
225
|
+
```toml
|
|
226
|
+
# pyproject.toml
|
|
227
|
+
[tool.black]
|
|
228
|
+
target-version = ['py38', 'py39', 'py310', 'py311', 'py312']
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Preview Features
|
|
232
|
+
```yaml
|
|
233
|
+
hooks:
|
|
234
|
+
pre-commit-black:
|
|
235
|
+
command: "black --preview ."
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## 高级配置
|
|
239
|
+
|
|
240
|
+
### Jupyter Notebook 支持
|
|
241
|
+
```yaml
|
|
242
|
+
hooks:
|
|
243
|
+
pre-commit-black:
|
|
244
|
+
command: "black --include '\.pyi?$|\.ipynb$' ."
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### 多个 Python 版本
|
|
248
|
+
```toml
|
|
249
|
+
# pyproject.toml
|
|
250
|
+
[tool.black]
|
|
251
|
+
target-version = ['py38', 'py39', 'py310', 'py311', 'py312']
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Performance Tips
|
|
255
|
+
|
|
256
|
+
### Use .gitignore for Exclusions
|
|
257
|
+
Black automatically respects `.gitignore` files, so large directories like `node_modules/` or `venv/` are automatically excluded.
|
|
258
|
+
|
|
259
|
+
### Format Only Changed Files
|
|
260
|
+
```bash
|
|
261
|
+
# Use with pre-commit framework for better performance
|
|
262
|
+
pip install pre-commit
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## 性能提示
|
|
266
|
+
|
|
267
|
+
### 使用 .gitignore 进行排除
|
|
268
|
+
Black 自动遵循 `.gitignore` 文件,因此像 `node_modules/` 或 `venv/` 这样的大目录会自动排除。
|
|
269
|
+
|
|
270
|
+
### 仅格式化更改的文件
|
|
271
|
+
```bash
|
|
272
|
+
# 使用 pre-commit 框架获得更好的性能
|
|
273
|
+
pip install pre-commit
|
|
274
|
+
```
|