auto-cr-rules 2.0.26 → 2.0.28
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 +59 -4
- package/README.zh-CN.md +59 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,15 +42,70 @@ Common flags:
|
|
|
42
42
|
|
|
43
43
|
- `--language <zh|en>`: Switch CLI output language (defaults to auto-detection).
|
|
44
44
|
- `--rule-dir <directory>`: Load additional custom rules from a directory or package.
|
|
45
|
+
- `--output <text|json>`: Choose between human-friendly text logs or structured JSON results (defaults to `text`).
|
|
45
46
|
- `--help`: Display the full command reference.
|
|
46
47
|
|
|
47
48
|
Sample output:
|
|
48
49
|
|
|
49
50
|
```text
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
WARN [12:56:18] ⚠️ [Base Rules]: no-deep-relative-imports
|
|
52
|
+
|
|
53
|
+
File: /Volumes/Wei/Codes/github/auto-cr/examples/src/app/features/admin/pages/dashboard.ts:2
|
|
54
|
+
Description: Import path "../../../../shared/deep/utils" must not exceed max depth 2
|
|
55
|
+
Code: ../../../../shared/deep/utils
|
|
56
|
+
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.
|
|
57
|
+
|
|
58
|
+
WARN [12:56:18] ⚠️ [untagged]: no-index-import
|
|
59
|
+
|
|
60
|
+
File: /Volumes/Wei/Codes/github/auto-cr/examples/src/app/features/admin/pages/dashboard.ts:3
|
|
61
|
+
Description: Import ../../consts/index is not allowed. Import the concrete file instead.
|
|
62
|
+
|
|
63
|
+
✔ Code scan complete, scanned 3 files: 0 with errors, 1 with warnings, 0 with optimizing hints!
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
JSON output sample:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npx auto-cr-cmd --output json -- ./src | jq
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"summary": {
|
|
75
|
+
"scannedFiles": 2,
|
|
76
|
+
"filesWithErrors": 1,
|
|
77
|
+
"filesWithWarnings": 0,
|
|
78
|
+
"filesWithOptimizing": 1,
|
|
79
|
+
"violationTotals": {
|
|
80
|
+
"total": 3,
|
|
81
|
+
"error": 2,
|
|
82
|
+
"warning": 0,
|
|
83
|
+
"optimizing": 1
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"files": [
|
|
87
|
+
{
|
|
88
|
+
"filePath": "/workspace/src/example.ts",
|
|
89
|
+
"severityCounts": {
|
|
90
|
+
"error": 2,
|
|
91
|
+
"warning": 0,
|
|
92
|
+
"optimizing": 1
|
|
93
|
+
},
|
|
94
|
+
"totalViolations": 3,
|
|
95
|
+
"errorViolations": 2,
|
|
96
|
+
"violations": [
|
|
97
|
+
{
|
|
98
|
+
"tag": "imports",
|
|
99
|
+
"ruleName": "no-deep-relative-imports",
|
|
100
|
+
"severity": "error",
|
|
101
|
+
"message": "Avoid deep relative imports from src/components/button",
|
|
102
|
+
"line": 13
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
"notifications": []
|
|
108
|
+
}
|
|
54
109
|
```
|
|
55
110
|
|
|
56
111
|
## Writing Custom Rules
|
package/README.zh-CN.md
CHANGED
|
@@ -42,15 +42,70 @@ npx auto-cr-cmd --language zh [需要扫描的代码目录]
|
|
|
42
42
|
|
|
43
43
|
- `--language <zh|en>`:切换 CLI 输出语言(默认为自动检测)。
|
|
44
44
|
- `--rule-dir <directory>`:加载额外的自定义规则目录或包。
|
|
45
|
+
- `--output <text|json>`:选择输出格式,`text` 为友好的终端日志,`json` 用于集成脚本(默认为 `text`)。
|
|
45
46
|
- `--help`:查看完整命令说明。
|
|
46
47
|
|
|
47
48
|
示例输出:
|
|
48
49
|
|
|
49
50
|
```text
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
WARN [12:52:48] ⚠️ [基础规则]:no-deep-relative-imports
|
|
52
|
+
|
|
53
|
+
文件位置: .../dashboard.ts:2
|
|
54
|
+
错误描述: 导入路径 "../../../../shared/deep/utils",不能超过最大层级2
|
|
55
|
+
错误代码: ../../../../shared/deep/utils
|
|
56
|
+
优化建议: 使用别名路径(如 @shared/deep/utils); 或在上层聚合导出,避免过深相对路径。
|
|
57
|
+
|
|
58
|
+
WARN [12:52:48] ⚠️ [未定义]:no-index-import
|
|
59
|
+
|
|
60
|
+
文件位置: .../dashboard.ts:3
|
|
61
|
+
错误描述: 禁止直接导入 ../../consts/index,请改用具体文件
|
|
62
|
+
|
|
63
|
+
✔ 代码扫描完成,本次共扫描3个文件,其中0个文件存在错误,1个文件存在警告,0个文件存在优化建议!
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
JSON 输出示例:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npx auto-cr-cmd --output json -- ./src | jq
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"summary": {
|
|
75
|
+
"scannedFiles": 2,
|
|
76
|
+
"filesWithErrors": 1,
|
|
77
|
+
"filesWithWarnings": 0,
|
|
78
|
+
"filesWithOptimizing": 1,
|
|
79
|
+
"violationTotals": {
|
|
80
|
+
"total": 3,
|
|
81
|
+
"error": 2,
|
|
82
|
+
"warning": 0,
|
|
83
|
+
"optimizing": 1
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"files": [
|
|
87
|
+
{
|
|
88
|
+
"filePath": "/workspace/src/example.ts",
|
|
89
|
+
"severityCounts": {
|
|
90
|
+
"error": 2,
|
|
91
|
+
"warning": 0,
|
|
92
|
+
"optimizing": 1
|
|
93
|
+
},
|
|
94
|
+
"totalViolations": 3,
|
|
95
|
+
"errorViolations": 2,
|
|
96
|
+
"violations": [
|
|
97
|
+
{
|
|
98
|
+
"tag": "imports",
|
|
99
|
+
"ruleName": "no-deep-relative-imports",
|
|
100
|
+
"severity": "error",
|
|
101
|
+
"message": "避免从 src/components/button 进行深层相对导入",
|
|
102
|
+
"line": 13
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
"notifications": []
|
|
108
|
+
}
|
|
54
109
|
```
|
|
55
110
|
|
|
56
111
|
## 编写自定义规则
|
package/package.json
CHANGED