coderev-cli 1.0.8 → 1.0.10
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 +182 -5
- package/package.json +1 -1
- package/src/cli.js +3 -0
- package/src/config.js +1 -2
package/README.md
CHANGED
|
@@ -131,34 +131,211 @@ coderev config show # 查看配置
|
|
|
131
131
|
|
|
132
132
|
## 配置管理
|
|
133
133
|
|
|
134
|
-
|
|
134
|
+
coderev 支持三种配置方式(优先级从高到低),建议用配置文件,一劳永逸。
|
|
135
|
+
|
|
136
|
+
### 方式一:全局配置文件
|
|
137
|
+
|
|
138
|
+
在项目根目录创建 `.coderevrc.json`,coderev 会自动从当前目录向父目录逐级查找。也支持 `.coderevrc` 或 `coderev.config.json` 作为文件名。
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# 一键生成默认配置
|
|
142
|
+
coderev init
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 方式二:环境变量
|
|
146
|
+
|
|
147
|
+
适用于临时测试或 CI 环境:
|
|
148
|
+
```bash
|
|
149
|
+
# Linux / macOS
|
|
150
|
+
export DEEPSEEK_API_KEY="sk-xxx"
|
|
151
|
+
export OPENAI_API_KEY="sk-xxx"
|
|
152
|
+
|
|
153
|
+
# Windows PowerShell
|
|
154
|
+
$env:DEEPSEEK_API_KEY="sk-xxx"
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
默认读取 `OPENAI_API_KEY`,如需改用 `DEEPSEEK_API_KEY`,在配置文件中设置:
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"ai": {
|
|
161
|
+
"apiKeyEnv": "DEEPSEEK_API_KEY"
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 方式三:配置文件内直接写 Key
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"ai": {
|
|
171
|
+
"apiKey": "sk-xxx"
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
> ⚠️ 注意:不要在公开仓库中提交含 Key 的配置文件,建议配合 `.gitignore` 或使用环境变量。
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
### 完整配置项说明
|
|
135
180
|
|
|
136
181
|
```json
|
|
137
182
|
{
|
|
138
183
|
"ai": {
|
|
139
184
|
"provider": "deepseek",
|
|
140
185
|
"model": "deepseek-chat",
|
|
141
|
-
"temperature": 0.3
|
|
186
|
+
"temperature": 0.3,
|
|
187
|
+
"maxTokens": 4096,
|
|
188
|
+
"apiKey": "",
|
|
189
|
+
"apiKeyEnv": "DEEPSEEK_API_KEY",
|
|
190
|
+
"baseURL": ""
|
|
142
191
|
},
|
|
143
192
|
"rules": {
|
|
144
193
|
"maxLineLength": 100,
|
|
145
194
|
"predefined": ["security", "performance", "style"],
|
|
195
|
+
"autoLanguage": true,
|
|
196
|
+
"custom": [
|
|
197
|
+
{
|
|
198
|
+
"name": "no-console-log",
|
|
199
|
+
"severity": "warning",
|
|
200
|
+
"message": "避免在生产代码中使用 console.log",
|
|
201
|
+
"filePattern": "src/**/*.js"
|
|
202
|
+
}
|
|
203
|
+
]
|
|
204
|
+
},
|
|
205
|
+
"output": {
|
|
206
|
+
"format": "terminal",
|
|
207
|
+
"includeScore": true
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
| 字段 | 类型 | 默认值 | 说明 |
|
|
213
|
+
|------|------|--------|------|
|
|
214
|
+
| `ai.provider` | string | `"openai"` | AI 提供商,支持 `"openai"` / `"deepseek"` |
|
|
215
|
+
| `ai.model` | string | 取决于 provider | 模型名称(openai 默认 `gpt-4o`,deepseek 默认 `deepseek-chat`)|
|
|
216
|
+
| `ai.temperature` | number | `0.3` | 生成温度,越低越确定(0-1) |
|
|
217
|
+
| `ai.maxTokens` | number | `4096` | 每次请求最大 token 数 |
|
|
218
|
+
| `ai.apiKey` | string | `""` | 直接在配置文件中写入 API Key |
|
|
219
|
+
| `ai.apiKeyEnv` | string | `"OPENAI_API_KEY"` | 从环境变量读取 Key 的变量名 |
|
|
220
|
+
| `ai.baseURL` | string | `""` | 自定义 API 地址(兼容 OpenAI 协议的任意服务) |
|
|
221
|
+
| `rules.maxLineLength` | number | `100` | 最大行长度检查 |
|
|
222
|
+
| `rules.predefined` | string[] | `["security","performance","style"]` | 启用的预定义规则集 |
|
|
223
|
+
| `rules.autoLanguage` | boolean | `true` | 是否自动检测 diff 语言并追加专项规则 |
|
|
224
|
+
| `rules.custom` | object[] | `[]` | 自定义规则数组 |
|
|
225
|
+
| `output.format` | string | `"terminal"` | 输出格式:`"terminal"` / `"markdown"` / `"json"` |
|
|
226
|
+
| `output.includeScore` | boolean | `true` | 是否显示评分 |
|
|
227
|
+
|
|
228
|
+
### 支持的 Provider
|
|
229
|
+
|
|
230
|
+
| provider | 默认模型 | 默认 API 地址 |
|
|
231
|
+
|----------|---------|--------------|
|
|
232
|
+
| `openai` | `gpt-4o` | `https://api.openai.com` |
|
|
233
|
+
| `deepseek` | `deepseek-chat` | `https://api.deepseek.com` |
|
|
234
|
+
|
|
235
|
+
通过 `ai.baseURL` 可对接任何兼容 OpenAI 协议的 API 服务(如 Azure OpenAI、本地 LLM 等)。
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
### 预定义规则集
|
|
240
|
+
|
|
241
|
+
`rules.predefined` 数组中可以启用以下规则集:
|
|
242
|
+
|
|
243
|
+
| 名称 | 说明 |
|
|
244
|
+
|------|------|
|
|
245
|
+
| `security` | 安全检查:注入、XSS、认证缺陷、密钥泄露 |
|
|
246
|
+
| `performance` | 性能检查:不必要的循环、内存泄漏、N+1 查询 |
|
|
247
|
+
| `style` | 代码风格:空格、import、未使用变量 |
|
|
248
|
+
| `typescript` | TypeScript 最佳实践(strict 模式、泛型、类型断言) |
|
|
249
|
+
| `react` | React 最佳实践(hooks 规则、key props、组件命名) |
|
|
250
|
+
| `node` | Node.js 最佳实践(错误处理、async 模式、文件安全) |
|
|
251
|
+
| `naming` | 命名规范(camelCase、PascalCase、常量大写) |
|
|
252
|
+
| `testing` | 测试质量(断言覆盖、边界情况、测试隔离) |
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
### 自定义规则
|
|
257
|
+
|
|
258
|
+
在 `rules.custom` 中定义专属规则:
|
|
259
|
+
|
|
260
|
+
```json
|
|
261
|
+
{
|
|
262
|
+
"rules": {
|
|
146
263
|
"custom": [
|
|
147
264
|
{
|
|
148
265
|
"name": "no-console-log",
|
|
149
266
|
"severity": "warning",
|
|
150
267
|
"message": "避免在生产代码中使用 console.log"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"name": "require-error-boundary",
|
|
271
|
+
"severity": "error",
|
|
272
|
+
"message": "React 组件必须包裹 ErrorBoundary",
|
|
273
|
+
"filePattern": "src/components/**/*.jsx"
|
|
151
274
|
}
|
|
152
275
|
]
|
|
153
276
|
}
|
|
154
277
|
}
|
|
155
278
|
```
|
|
156
279
|
|
|
157
|
-
|
|
280
|
+
| 字段 | 说明 |
|
|
281
|
+
|------|------|
|
|
282
|
+
| `name` | 规则名称 |
|
|
283
|
+
| `severity` | 严重级别:`"error"` / `"warning"` / `"info"` |
|
|
284
|
+
| `message` | 审查时的提示文字 |
|
|
285
|
+
| `filePattern` | 可选,限定生效的文件 glob 模式 |
|
|
286
|
+
| `enabled` | 可选,设为 `false` 可临时禁用 |
|
|
158
287
|
|
|
159
|
-
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
### 语言专项规则
|
|
291
|
+
|
|
292
|
+
coderev 自动从 diff 文件扩展名检测语言,追加专项检查(可通过 `rules.autoLanguage: false` 关闭):
|
|
293
|
+
|
|
294
|
+
| 语言 | 检查重点 |
|
|
295
|
+
|------|---------|
|
|
296
|
+
| JavaScript | async/await 链、== vs ===、内存泄漏、import 循环依赖 |
|
|
297
|
+
| TypeScript | strict 模式、避免 any、泛型、类型断言 |
|
|
298
|
+
| Python | PEP 8、except 类型、mutable 默认参数、async 用法 |
|
|
299
|
+
| Rust | unsafe 审计、unwrap/expect、生命周期、ownership |
|
|
300
|
+
| Go | error handling、goroutine 安全、context 传播、data race |
|
|
301
|
+
| Java | null 处理、checked exception、== vs .equals()、线程安全 |
|
|
302
|
+
| SQL | 注入防护、N+1 查询、索引缺失、大 IN-clause |
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
### .coderevignore:忽略文件
|
|
307
|
+
|
|
308
|
+
不想被审查的文件,在 `.coderevignore` 中列出(glob 模式):
|
|
309
|
+
|
|
310
|
+
```
|
|
311
|
+
# coderev ignore list
|
|
312
|
+
*.min.js
|
|
313
|
+
*.bundle.js
|
|
314
|
+
package-lock.json
|
|
315
|
+
yarn.lock
|
|
316
|
+
vendor/
|
|
317
|
+
dist/
|
|
318
|
+
build/
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
### .coderevhint:项目上下文
|
|
324
|
+
|
|
325
|
+
给 AI 审查提供项目背景,让它更懂你的代码:
|
|
326
|
+
|
|
327
|
+
```
|
|
328
|
+
# 项目概况
|
|
329
|
+
- Language: TypeScript
|
|
330
|
+
- Framework: Next.js 14
|
|
331
|
+
- Database: PostgreSQL
|
|
332
|
+
|
|
333
|
+
# 编码规范
|
|
334
|
+
- Prefer: 函数式组件、Tailwind CSS、Server Actions
|
|
335
|
+
- Avoid: any 类型、使用 any 断言
|
|
336
|
+
```
|
|
160
337
|
|
|
161
|
-
|
|
338
|
+
兼容 `CLAUDE.md` 格式,两者可共存。
|
|
162
339
|
|
|
163
340
|
---
|
|
164
341
|
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
package/src/config.js
CHANGED