🎯 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.
🔧 auto-cr-rules provides an extensible static analysis rule set and SDK so you can tailor enterprise-grade review policies with minimal effort.
📘 Prefer Chinese? Read the Chinese README.
- Built-in Rule Library: Ships with SWC AST static analysis rules out of the box, such as
no-deep-relative-imports
. - Extensible SDK:
auto-cr-rules
exposes helpers likedefineRule
andhelpers.imports
, reducing the friction of authoring custom TypeScript / JavaScript rules. - Workspace Friendly: Manage both the CLI and rule package via pnpm workspaces and validate the full pipeline with a single build.
- Publishing Toolkit: Version bump scripts and npm publish commands keep both packages in sync.
Package Overview (auto-cr-cmd & auto-cr-rules)
- auto-cr-cmd: A lightning-fast SWC-based CLI focused on automated reviews, CI integration, and static code scanning.
- auto-cr-rules: A developer-facing rule SDK with tag-based grouping, internationalized messaging, and support for publishing team-specific rules.
npx auto-cr-cmd --language en [path-to-your-code]
Common flags:
--language <zh|en>
: Switch CLI output language (defaults to auto-detection).--rule-dir <directory>
: Load additional custom rules from a directory or package.--output <text|json>
: Choose between human-friendly text logs or structured JSON results (defaults totext
).--help
: Display the full command reference.
Sample output:
WARN [12:56:18] ⚠️ [Base Rules]: no-deep-relative-imports
File: /Volumes/Wei/Codes/github/auto-cr/examples/src/app/features/admin/pages/dashboard.ts:2
Description: Import path "../../../../shared/deep/utils" must not exceed max depth 2
Code: ../../../../shared/deep/utils
Suggestion: Use a path alias (for example: @shared/deep/utils). | Create an index file at a higher level to re-export the module and shorten the import.
WARN [12:56:18] ⚠️ [untagged]: no-index-import
File: /Volumes/Wei/Codes/github/auto-cr/examples/src/app/features/admin/pages/dashboard.ts:3
Description: Import ../../consts/index is not allowed. Import the concrete file instead.
✔ Code scan complete, scanned 3 files: 0 with errors, 1 with warnings, 0 with optimizing hints!
JSON output sample:
npx auto-cr-cmd --output json -- ./src | jq
{
"summary": {
"scannedFiles": 2,
"filesWithErrors": 1,
"filesWithWarnings": 0,
"filesWithOptimizing": 1,
"violationTotals": {
"total": 3,
"error": 2,
"warning": 0,
"optimizing": 1
}
},
"files": [
{
"filePath": "/workspace/src/example.ts",
"severityCounts": {
"error": 2,
"warning": 0,
"optimizing": 1
},
"totalViolations": 3,
"errorViolations": 2,
"violations": [
{
"tag": "imports",
"ruleName": "no-deep-relative-imports",
"severity": "error",
"message": "Avoid deep relative imports from src/components/button",
"line": 13
}
]
}
],
"notifications": []
}
The CLI consumes rules from the auto-cr-rules
package by default, and you can extend it with your own logic.
mkdir custom-rules
Place Node.js-compatible .js
/ .cjs
/ .mjs
files inside the directory.
pnpm add auto-cr-rules
// custom-rules/no-index-import.js
const { defineRule } = require('auto-cr-rules')
module.exports = defineRule('no-index-import', ({ helpers, language }) => {
for (const ref of helpers.imports) {
if (ref.value.endsWith('/index')) {
const message =
language === 'zh'
? `禁止直接导入 ${ref.value},请改用具体文件`
: `Import ${ref.value} is not allowed. Import the concrete file instead.`
helpers.reportViolation(message, ref.span)
}
}
})
RuleContext
offers:
helpers.imports
: Normalizedimport
/require
/ dynamic import references.helpers.isRelativePath
,helpers.relativeDepth
: Common path utilities.helpers.reportViolation(message, span?)
: Unified reporting API.language
andreporter
: Access the active language and low-level reporter APIs.
You can export multiple rules at once:
const { defineRule } = require('auto-cr-rules')
const ruleA = defineRule('rule-a', (context) => { /* ... */ })
const ruleB = defineRule('rule-b', (context) => { /* ... */ })
module.exports = { rules: [ruleA, ruleB] }
cd examples
npx auto-cr-cmd -l zh -r ./custom-rules/rules -- ./custom-rules/demo
packages/
auto-cr-rules/ # Rule SDK and built-in rules (createRuleContext, defineRule, etc.)
auto-cr-cmd/ # CLI entry point, reporter, i18n, and command handling
scripts/
bump-version.mjs # Keep both package versions aligned
examples/
custom-rules # Custom rule samples
src # Example that triggers the base rule
Essential scripts:
pnpm run version [major|minor|patch]
: Bump both packages together (defaults to patch).pnpm run publish
: Run version bump, build, and publish for both packages sequentially.
We welcome contributions through Issues or Pull Requests. Please read:
- Issues: Issue Tracker
- Discussions: Community Discussions
Auto CR © [2025] [dengfengwang]. Licensed under the MIT License