auto-cr-cmd 2.0.13 → 2.0.14
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-cr-cmd",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.14",
|
|
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",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@swc/core": "^1.13.20",
|
|
40
40
|
"@swc/wasm": "^1.13.20",
|
|
41
|
-
"auto-cr-rules": "^2.0.
|
|
41
|
+
"auto-cr-rules": "^2.0.14",
|
|
42
42
|
"commander": "^14.0.0",
|
|
43
43
|
"consola": "^3.4.2"
|
|
44
44
|
},
|
package/dist/README.md
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
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)
|
|
File without changes
|