auto-cr-cmd 2.0.11 → 2.0.13
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 +150 -0
- package/dist/README.md +150 -0
- package/dist/README.zh-CN.md +151 -0
- package/package.json +4 -5
package/README.md
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/wangweiwei/auto-cr">
|
|
3
|
+
<img src="https://github.com/wangweiwei/auto-cr/blob/main/assets/images/image.png?raw=true" alt="auto-cr logo" width="60" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">Automated Code Review CLI ⚡️</h1>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/auto-cr-cmd"><img alt="NPM Version" src="https://img.shields.io/npm/v/auto-cr-cmd.svg?style=flat"/></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/auto-cr-cmd"><img alt="NPM Downloads" src="https://img.shields.io/npm/dm/auto-cr-cmd.svg?style=flat"/></a>
|
|
12
|
+
<a href="./LICENSE"><img alt="MIT License" src="https://img.shields.io/github/license/wangweiwei/auto-cr"/></a>
|
|
13
|
+
<a href="https://github.com/wangweiwei/auto-cr/stargazers"><img alt="GitHub Stars" src="https://img.shields.io/github/stars/wangweiwei/auto-cr" /></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
> 🎯 auto-cr-cmd is a high-speed automated code review CLI powered by SWC static analysis, built for JavaScript / TypeScript teams to surface risky code before it merges.
|
|
17
|
+
>
|
|
18
|
+
> 🔧 auto-cr-rules provides an extensible static analysis rule set and SDK so you can tailor enterprise-grade review policies with minimal effort.
|
|
19
|
+
|
|
20
|
+
📘 Prefer Chinese? Read the [Chinese README](https://github.com/wangweiwei/auto-cr/blob/main/README.zh-CN.md).
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## Feature Highlights (Automated Code Review & Static Analysis)
|
|
24
|
+
|
|
25
|
+
- **Built-in Rule Library**: Ships with SWC AST static analysis rules out of the box, such as `no-deep-relative-imports`.
|
|
26
|
+
- **Extensible SDK**: `auto-cr-rules` exposes helpers like `defineRule` and `helpers.imports`, reducing the friction of authoring custom TypeScript / JavaScript rules.
|
|
27
|
+
- **Workspace Friendly**: Manage both the CLI and rule package via pnpm workspaces and validate the full pipeline with a single build.
|
|
28
|
+
- **Publishing Toolkit**: Version bump scripts and npm publish commands keep both packages in sync.
|
|
29
|
+
|
|
30
|
+
## Package Overview (auto-cr-cmd & auto-cr-rules)
|
|
31
|
+
|
|
32
|
+
- **auto-cr-cmd**: A lightning-fast SWC-based CLI focused on automated reviews, CI integration, and static code scanning.
|
|
33
|
+
- **auto-cr-rules**: A developer-facing rule SDK with tag-based grouping, internationalized messaging, and support for publishing team-specific rules.
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx auto-cr-cmd --language en [path-to-your-code]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Common flags:
|
|
42
|
+
|
|
43
|
+
- `--language <zh|en>`: Switch CLI output language (defaults to auto-detection).
|
|
44
|
+
- `--rule-dir <directory>`: Load additional custom rules from a directory or package.
|
|
45
|
+
- `--help`: Display the full command reference.
|
|
46
|
+
|
|
47
|
+
Sample output:
|
|
48
|
+
|
|
49
|
+
```text
|
|
50
|
+
ℹ️ Scanning directory: ./src
|
|
51
|
+
ℹ️ Scanning file: ./src/main.ts
|
|
52
|
+
ℹ️ [Base Rules]
|
|
53
|
+
✔ auto-cr scan complete
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Writing Custom Rules
|
|
57
|
+
|
|
58
|
+
The CLI consumes rules from the `auto-cr-rules` package by default, and you can extend it with your own logic.
|
|
59
|
+
|
|
60
|
+
### 1. Prepare a Directory
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
mkdir custom-rules
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Place Node.js-compatible `.js` / `.cjs` / `.mjs` files inside the directory.
|
|
67
|
+
|
|
68
|
+
### 2. Install the SDK
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pnpm add auto-cr-rules
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 3. Implement a Rule
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
// custom-rules/no-index-import.js
|
|
78
|
+
const { defineRule } = require('auto-cr-rules')
|
|
79
|
+
|
|
80
|
+
module.exports = defineRule('no-index-import', ({ helpers, language }) => {
|
|
81
|
+
for (const ref of helpers.imports) {
|
|
82
|
+
if (ref.value.endsWith('/index')) {
|
|
83
|
+
const message =
|
|
84
|
+
language === 'zh'
|
|
85
|
+
? `禁止直接导入 ${ref.value},请改用具体文件`
|
|
86
|
+
: `Import ${ref.value} is not allowed. Import the concrete file instead.`
|
|
87
|
+
|
|
88
|
+
helpers.reportViolation(message, ref.span)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`RuleContext` offers:
|
|
95
|
+
|
|
96
|
+
- `helpers.imports`: Normalized `import` / `require` / dynamic import references.
|
|
97
|
+
- `helpers.isRelativePath`, `helpers.relativeDepth`: Common path utilities.
|
|
98
|
+
- `helpers.reportViolation(message, span?)`: Unified reporting API.
|
|
99
|
+
- `language` and `reporter`: Access the active language and low-level reporter APIs.
|
|
100
|
+
|
|
101
|
+
You can export multiple rules at once:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
const { defineRule } = require('auto-cr-rules')
|
|
105
|
+
|
|
106
|
+
const ruleA = defineRule('rule-a', (context) => { /* ... */ })
|
|
107
|
+
const ruleB = defineRule('rule-b', (context) => { /* ... */ })
|
|
108
|
+
|
|
109
|
+
module.exports = { rules: [ruleA, ruleB] }
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 4. Run It
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
npx auto-cr-cmd --language en --rule-dir ./examples/custom-rules -- ./examples/src
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Project Layout
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
packages/
|
|
122
|
+
auto-cr-rules/ # Rule SDK and built-in rules (createRuleContext, defineRule, etc.)
|
|
123
|
+
auto-cr-cmd/ # CLI entry point, reporter, i18n, and command handling
|
|
124
|
+
scripts/
|
|
125
|
+
bump-version.mjs # Keep both package versions aligned
|
|
126
|
+
examples/
|
|
127
|
+
custom-rules # Custom rule samples
|
|
128
|
+
src # Example that triggers the base rule
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Essential scripts:
|
|
132
|
+
|
|
133
|
+
- `pnpm run version [major|minor|patch]`: Bump both packages together (defaults to patch).
|
|
134
|
+
- `pnpm run publish`: Run version bump, build, and publish for both packages sequentially.
|
|
135
|
+
|
|
136
|
+
## Contributing
|
|
137
|
+
|
|
138
|
+
We welcome contributions through Issues or Pull Requests. Please read:
|
|
139
|
+
|
|
140
|
+
- [Code of Conduct](./CODE_OF_CONDUCT.md)
|
|
141
|
+
- [Contributing Guide](./CONTRIBUTING.md)
|
|
142
|
+
|
|
143
|
+
## Community & Support
|
|
144
|
+
|
|
145
|
+
- Issues: [Issue Tracker](https://github.com/wangweiwei/auto-cr/issues)
|
|
146
|
+
- Discussions: [Community Discussions](https://github.com/wangweiwei/auto-cr/wiki)
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
Auto CR © [2025] [dengfengwang]. Licensed under the [MIT License](./LICENSE)
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/wangweiwei/auto-cr">
|
|
3
|
+
<img src="https://github.com/wangweiwei/auto-cr/blob/main/assets/images/image.png?raw=true" alt="auto-cr logo" width="60" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">Automated Code Review CLI ⚡️</h1>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/auto-cr-cmd"><img alt="NPM Version" src="https://img.shields.io/npm/v/auto-cr-cmd.svg?style=flat"/></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/auto-cr-cmd"><img alt="NPM Downloads" src="https://img.shields.io/npm/dm/auto-cr-cmd.svg?style=flat"/></a>
|
|
12
|
+
<a href="./LICENSE"><img alt="MIT License" src="https://img.shields.io/github/license/wangweiwei/auto-cr"/></a>
|
|
13
|
+
<a href="https://github.com/wangweiwei/auto-cr/stargazers"><img alt="GitHub Stars" src="https://img.shields.io/github/stars/wangweiwei/auto-cr" /></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
> 🎯 auto-cr-cmd is a high-speed automated code review CLI powered by SWC static analysis, built for JavaScript / TypeScript teams to surface risky code before it merges.
|
|
17
|
+
>
|
|
18
|
+
> 🔧 auto-cr-rules provides an extensible static analysis rule set and SDK so you can tailor enterprise-grade review policies with minimal effort.
|
|
19
|
+
|
|
20
|
+
📘 Prefer Chinese? Read the [Chinese README](https://github.com/wangweiwei/auto-cr/blob/main/README.zh-CN.md).
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## Feature Highlights (Automated Code Review & Static Analysis)
|
|
24
|
+
|
|
25
|
+
- **Built-in Rule Library**: Ships with SWC AST static analysis rules out of the box, such as `no-deep-relative-imports`.
|
|
26
|
+
- **Extensible SDK**: `auto-cr-rules` exposes helpers like `defineRule` and `helpers.imports`, reducing the friction of authoring custom TypeScript / JavaScript rules.
|
|
27
|
+
- **Workspace Friendly**: Manage both the CLI and rule package via pnpm workspaces and validate the full pipeline with a single build.
|
|
28
|
+
- **Publishing Toolkit**: Version bump scripts and npm publish commands keep both packages in sync.
|
|
29
|
+
|
|
30
|
+
## Package Overview (auto-cr-cmd & auto-cr-rules)
|
|
31
|
+
|
|
32
|
+
- **auto-cr-cmd**: A lightning-fast SWC-based CLI focused on automated reviews, CI integration, and static code scanning.
|
|
33
|
+
- **auto-cr-rules**: A developer-facing rule SDK with tag-based grouping, internationalized messaging, and support for publishing team-specific rules.
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx auto-cr-cmd --language en [path-to-your-code]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Common flags:
|
|
42
|
+
|
|
43
|
+
- `--language <zh|en>`: Switch CLI output language (defaults to auto-detection).
|
|
44
|
+
- `--rule-dir <directory>`: Load additional custom rules from a directory or package.
|
|
45
|
+
- `--help`: Display the full command reference.
|
|
46
|
+
|
|
47
|
+
Sample output:
|
|
48
|
+
|
|
49
|
+
```text
|
|
50
|
+
ℹ️ Scanning directory: ./src
|
|
51
|
+
ℹ️ Scanning file: ./src/main.ts
|
|
52
|
+
ℹ️ [Base Rules]
|
|
53
|
+
✔ auto-cr scan complete
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Writing Custom Rules
|
|
57
|
+
|
|
58
|
+
The CLI consumes rules from the `auto-cr-rules` package by default, and you can extend it with your own logic.
|
|
59
|
+
|
|
60
|
+
### 1. Prepare a Directory
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
mkdir custom-rules
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Place Node.js-compatible `.js` / `.cjs` / `.mjs` files inside the directory.
|
|
67
|
+
|
|
68
|
+
### 2. Install the SDK
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pnpm add auto-cr-rules
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 3. Implement a Rule
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
// custom-rules/no-index-import.js
|
|
78
|
+
const { defineRule } = require('auto-cr-rules')
|
|
79
|
+
|
|
80
|
+
module.exports = defineRule('no-index-import', ({ helpers, language }) => {
|
|
81
|
+
for (const ref of helpers.imports) {
|
|
82
|
+
if (ref.value.endsWith('/index')) {
|
|
83
|
+
const message =
|
|
84
|
+
language === 'zh'
|
|
85
|
+
? `禁止直接导入 ${ref.value},请改用具体文件`
|
|
86
|
+
: `Import ${ref.value} is not allowed. Import the concrete file instead.`
|
|
87
|
+
|
|
88
|
+
helpers.reportViolation(message, ref.span)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`RuleContext` offers:
|
|
95
|
+
|
|
96
|
+
- `helpers.imports`: Normalized `import` / `require` / dynamic import references.
|
|
97
|
+
- `helpers.isRelativePath`, `helpers.relativeDepth`: Common path utilities.
|
|
98
|
+
- `helpers.reportViolation(message, span?)`: Unified reporting API.
|
|
99
|
+
- `language` and `reporter`: Access the active language and low-level reporter APIs.
|
|
100
|
+
|
|
101
|
+
You can export multiple rules at once:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
const { defineRule } = require('auto-cr-rules')
|
|
105
|
+
|
|
106
|
+
const ruleA = defineRule('rule-a', (context) => { /* ... */ })
|
|
107
|
+
const ruleB = defineRule('rule-b', (context) => { /* ... */ })
|
|
108
|
+
|
|
109
|
+
module.exports = { rules: [ruleA, ruleB] }
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 4. Run It
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
npx auto-cr-cmd --language en --rule-dir ./examples/custom-rules -- ./examples/src
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Project Layout
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
packages/
|
|
122
|
+
auto-cr-rules/ # Rule SDK and built-in rules (createRuleContext, defineRule, etc.)
|
|
123
|
+
auto-cr-cmd/ # CLI entry point, reporter, i18n, and command handling
|
|
124
|
+
scripts/
|
|
125
|
+
bump-version.mjs # Keep both package versions aligned
|
|
126
|
+
examples/
|
|
127
|
+
custom-rules # Custom rule samples
|
|
128
|
+
src # Example that triggers the base rule
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Essential scripts:
|
|
132
|
+
|
|
133
|
+
- `pnpm run version [major|minor|patch]`: Bump both packages together (defaults to patch).
|
|
134
|
+
- `pnpm run publish`: Run version bump, build, and publish for both packages sequentially.
|
|
135
|
+
|
|
136
|
+
## Contributing
|
|
137
|
+
|
|
138
|
+
We welcome contributions through Issues or Pull Requests. Please read:
|
|
139
|
+
|
|
140
|
+
- [Code of Conduct](./CODE_OF_CONDUCT.md)
|
|
141
|
+
- [Contributing Guide](./CONTRIBUTING.md)
|
|
142
|
+
|
|
143
|
+
## Community & Support
|
|
144
|
+
|
|
145
|
+
- Issues: [Issue Tracker](https://github.com/wangweiwei/auto-cr/issues)
|
|
146
|
+
- Discussions: [Community Discussions](https://github.com/wangweiwei/auto-cr/wiki)
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
Auto CR © [2025] [dengfengwang]. Licensed under the [MIT License](./LICENSE)
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/wangweiwei/auto-cr">
|
|
3
|
+
<img src="https://github.com/wangweiwei/auto-cr/blob/main/assets/images/image.png?raw=true" alt="auto-cr logo" width="60" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">自动化代码审查 CLI ⚡️</h1>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/auto-cr-cmd"><img alt="NPM Version" src="https://img.shields.io/npm/v/auto-cr-cmd.svg?style=flat"/></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/auto-cr-cmd"><img alt="NPM Downloads" src="https://img.shields.io/npm/dm/auto-cr-cmd.svg?style=flat"/></a>
|
|
12
|
+
<a href="./LICENSE"><img alt="MIT License" src="https://img.shields.io/github/license/wangweiwei/auto-cr"/></a>
|
|
13
|
+
<a href="https://github.com/wangweiwei/auto-cr/stargazers"><img alt="GitHub Stars" src="https://img.shields.io/github/stars/wangweiwei/auto-cr" /></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
> 🎯 auto-cr-cmd 是一个基于 SWC 静态分析的高速自动化代码审查 CLI,专为 JavaScript / TypeScript 团队设计,可在合并前快速发现风险代码。
|
|
17
|
+
|
|
18
|
+
> 🔧 auto-cr-rules 提供可扩展的静态分析规则集与 SDK,帮你零成本定制企业级代码审查策略。
|
|
19
|
+
|
|
20
|
+
📘 Prefer English? Read the [English README](https://github.com/wangweiwei/auto-cr/blob/main/README.md).
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## 特性亮点(自动化代码审查 & 静态代码分析)
|
|
24
|
+
|
|
25
|
+
- **内置规则库**:默认集成 SWC AST 静态分析规则,例如 `no-deep-relative-imports`。
|
|
26
|
+
- **可扩展 SDK**:`auto-cr-rules` 暴露 `defineRule`、`helpers.imports` 等工具,降低编写 TypeScript / JavaScript 自定义规则的复杂度。
|
|
27
|
+
- **工作区管理**:使用 pnpm workspace 同时管理 CLI 与规则包,一次构建即可验证完整流程。
|
|
28
|
+
- **发布友好**:内置版本递增脚本与 npm 发布命令,保持两个包的版本同步。
|
|
29
|
+
|
|
30
|
+
## 包概览(auto-cr-cmd & auto-cr-rules)
|
|
31
|
+
|
|
32
|
+
- **auto-cr-cmd**:基于 SWC 的极速命令行工具,聚焦自动化代码审查、CI 集成与静态代码扫描。
|
|
33
|
+
- **auto-cr-rules**:面向开发者的规则 SDK,支持多标签分类、国际化提示与团队定制规则发布。
|
|
34
|
+
|
|
35
|
+
## 快速开始
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx auto-cr-cmd --language zh [需要扫描的代码目录]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
常用参数:
|
|
42
|
+
|
|
43
|
+
- `--language <zh|en>`:切换 CLI 输出语言(默认为自动检测)。
|
|
44
|
+
- `--rule-dir <directory>`:加载额外的自定义规则目录或包。
|
|
45
|
+
- `--help`:查看完整命令说明。
|
|
46
|
+
|
|
47
|
+
示例输出:
|
|
48
|
+
|
|
49
|
+
```text
|
|
50
|
+
ℹ️ 扫描目录: ./src
|
|
51
|
+
ℹ️ 扫描文件: ./src/main.ts
|
|
52
|
+
ℹ️ [基础规则]
|
|
53
|
+
✔ auto-cr 代码扫描完成
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## 编写自定义规则
|
|
57
|
+
|
|
58
|
+
CLI 默认使用 `auto-cr-rules` 包提供的规则,你也可以扩展自己的逻辑。
|
|
59
|
+
|
|
60
|
+
### 1. 准备目录
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
mkdir custom-rules
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
目录内放置可被 Node.js 执行的 `.js` / `.cjs` / `.mjs` 文件。
|
|
67
|
+
|
|
68
|
+
### 2. 安装 SDK
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pnpm add auto-cr-rules
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 3. 编写规则
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
// custom-rules/no-index-import.js
|
|
78
|
+
const { defineRule } = require('auto-cr-rules')
|
|
79
|
+
|
|
80
|
+
module.exports = defineRule('no-index-import', ({ helpers, language }) => {
|
|
81
|
+
for (const ref of helpers.imports) {
|
|
82
|
+
if (ref.value.endsWith('/index')) {
|
|
83
|
+
const message =
|
|
84
|
+
language === 'zh'
|
|
85
|
+
? `禁止直接导入 ${ref.value},请改用具体文件`
|
|
86
|
+
: `Import ${ref.value} is not allowed. Import the concrete file instead.`
|
|
87
|
+
|
|
88
|
+
helpers.reportViolation(message, ref.span)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`RuleContext` 提供:
|
|
95
|
+
|
|
96
|
+
- `helpers.imports`:统一收集的 `import` / `require` / 动态导入引用。
|
|
97
|
+
- `helpers.isRelativePath`、`helpers.relativeDepth`:常见路径判断工具。
|
|
98
|
+
- `helpers.reportViolation(message, span?)`:统一的问题上报接口。
|
|
99
|
+
- `language` 与 `reporter`:可获取当前语言和底层 Reporter API。
|
|
100
|
+
|
|
101
|
+
也可以一次导出多个规则:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
const { defineRule } = require('auto-cr-rules')
|
|
105
|
+
|
|
106
|
+
const ruleA = defineRule('rule-a', (context) => { /* ... */ })
|
|
107
|
+
const ruleB = defineRule('rule-b', (context) => { /* ... */ })
|
|
108
|
+
|
|
109
|
+
module.exports = { rules: [ruleA, ruleB] }
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 4. 运行
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
pnpm run build
|
|
116
|
+
npx auto-cr-cmd --language zh --rule-dir ./examples/custom-rules -- ./examples/src
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## 项目结构
|
|
120
|
+
|
|
121
|
+
```text
|
|
122
|
+
packages/
|
|
123
|
+
auto-cr-rules/ # 规则 SDK 与内置规则(createRuleContext、defineRule 等)
|
|
124
|
+
auto-cr-cmd/ # CLI 入口、Reporter、I18n、命令行逻辑
|
|
125
|
+
scripts/
|
|
126
|
+
bump-version.mjs # 统一递增两个包的版本号
|
|
127
|
+
examples/
|
|
128
|
+
custom-rules # 自定义规则
|
|
129
|
+
src # 触发基础规则的例子
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
核心脚本:
|
|
133
|
+
|
|
134
|
+
- `pnpm run version [major|minor|patch]`:统一更新两个包的版本号(默认 patch)。
|
|
135
|
+
- `pnpm run publish`:依次执行版本递增、构建与两个包的 npm 发布。
|
|
136
|
+
|
|
137
|
+
## 参与贡献
|
|
138
|
+
|
|
139
|
+
欢迎通过 Issue 或 Pull Request 贡献代码。请先阅读:
|
|
140
|
+
|
|
141
|
+
- [行为准则](./CODE_OF_CONDUCT.md)
|
|
142
|
+
- [贡献指南](./CONTRIBUTING.md)
|
|
143
|
+
|
|
144
|
+
## 社区与支持
|
|
145
|
+
|
|
146
|
+
- 问题反馈:[Issue Tracker](https://github.com/wangweiwei/auto-cr/issues)
|
|
147
|
+
- 讨论社区:[Community Discussions](https://github.com/wangweiwei/auto-cr/wiki)
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
Auto CR © [2025] [dengfengwang]。许可协议: [MIT License](./LICENSE)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-cr-cmd",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.13",
|
|
4
4
|
"description": "Fast automated code review CLI powered by SWC-based static analysis",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -11,16 +11,15 @@
|
|
|
11
11
|
"dist"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
-
"prebuild": "node ../../scripts/readme-sync.mjs copy auto-cr-cmd",
|
|
15
14
|
"build": "tsc --build tsconfig.json",
|
|
16
15
|
"build:force": "tsc --build tsconfig.json --force",
|
|
17
|
-
"
|
|
16
|
+
"postbuild": "node ../../scripts/readme-sync.mjs copy auto-cr-cmd",
|
|
17
|
+
"postbuild:force": "node ../../scripts/readme-sync.mjs copy auto-cr-cmd",
|
|
18
18
|
"dev": "tsc --watch",
|
|
19
19
|
"start": "node dist/index.js",
|
|
20
20
|
"cli": "ts-node src/index.ts",
|
|
21
21
|
"prepublishOnly": "pnpm run build",
|
|
22
22
|
"release": "pnpm run build && npm publish --access public",
|
|
23
|
-
"postrelease": "node ../../scripts/readme-sync.mjs clean auto-cr-cmd",
|
|
24
23
|
"format": "prettier --write src"
|
|
25
24
|
},
|
|
26
25
|
"keywords": [
|
|
@@ -39,7 +38,7 @@
|
|
|
39
38
|
"dependencies": {
|
|
40
39
|
"@swc/core": "^1.13.20",
|
|
41
40
|
"@swc/wasm": "^1.13.20",
|
|
42
|
-
"auto-cr-rules": "^2.0.
|
|
41
|
+
"auto-cr-rules": "^2.0.13",
|
|
43
42
|
"commander": "^14.0.0",
|
|
44
43
|
"consola": "^3.4.2"
|
|
45
44
|
},
|