auto-cr-cmd是一个基于 AST(抽象语法树)分析的命令行工具,用于检查代码是否符合预定义的规则集。它支持灵活定制规则,并可集成到 CI/CD 流程中,助力团队实现代码质量的自动化管控
- ✅ AST 分析:通过解析代码的抽象语法树深度检测代码结构
- ✅ 规则定制:支持用户自定义规则
- ⬜ report 定制接口
- ⬜ 集成到 CI/CD 流程
- ……
npm install -g auto-cr-cmd
git clone https://github.com/your-repo/auto-cr-cmd.git
cd auto-cr-cmd
pnpm install
pnpm build
- 编写规则
// rules/my-rules.js
module.exports = function (api, options) {
// 从插件参数中获取 report 方法
const { report } = options;
return {
name: "my-custom-plugin",
visitor: {
// 遍历 FunctionDeclaration 节点
FunctionDeclaration(path) {
const functionName = path.node.id.name;
// 执行业务逻辑
if (functionName === "badFunction") {
// 通过 report 上报问题
report(path, "Function name 'badFunction' is not allowed.");
}
},
},
};
}
- 将规则文件放入指定目录,然后执行如下命令即可
npx auto-cr-cmd -r xxxx/rules xxx/src
- [paths...] 需要扫描的文件或目录路径列表
- -r 自定义规则目录路径
欢迎提交 Issue 或 Pull Request:
- Fork 本项目
- 为auto-cr-rules添加新规则或优化现有规则
- 测试通过后提交 PR