AC Code Validator 是一个代码质量与规范验证工具,主要用于在代码集成前执行静态分析、代码检查、类型检查、格式校验和安全扫描,以确保代码符合既定的质量标准与风格指南。
用途 该工具的核心用途是对代码进行多维度验证,覆盖代码检查(linting)、类型检查、格式化和安全扫描,帮助开发者在集成前发现并修复问题。
主要能力
- 代码检查(Linting):支持 ESLint(JS/TS)、Ruff/Flake8(Python)、golint(Go)。
- 类型检查(Type Checking):支持 TypeScript 编译器、mypy(Python)、go vet(Go)。
- 格式化检查(Formatting):支持 Prettier(JS/TS)、Black(Python)、gofmt(Go)。
- 安全扫描(Security Scan):支持 Bandit(Python)、npm audit(Node.js)、gosec(Go)。
- 自动修复(Auto-Fix):可修复所有可自动修复的问题,也可指定仅修复特定类型(如 format、lint)。
- 统一验证结果:返回 JSON 格式结果,包含 valid 状态、各检查项的 passed、errors、warnings、issues 列表,以及 summary 中的 total_issues、blocking、auto_fixable 统计。
使用方式 通过 Python 导入使用: from scripts.code_validator import CodeValidator validator = CodeValidator(project_dir) result = await validator.validate()
可分别调用各验证方法:
- await validator.run_lint()
- await validator.run_type_check()
- await validator.check_formatting()
- await validator.run_security_scan()
自动修复:
- await validator.auto_fix()
- await validator.auto_fix(types=["format", "lint"])
配置 支持通过配置对象指定语言、工具、规则和忽略模式。示例配置包括:
- language: "python"
- tools: { lint: "ruff", format: "black", types: "mypy", security: "bandit" }
- rules: { max_line_length: 100, max_complexity: 10, require_docstrings: true }
- ignore_patterns: ["/pycache/", "/node_modules/", "/.venv/"]
语言支持
- Python:ruff/flake8、mypy、black、bandit
- TypeScript:eslint、tsc、prettier、npm audit
- JavaScript:eslint、-、prettier、npm audit
- Go:golint、go vet、gofmt、gosec
集成 该工具被 ac-qa-reviewer 用于质量检查,被 ac-commit-manager 在提交前使用,并向 ac-task-executor 报告。
API 参考 完整实现参见 scripts/code_validator.py。
限制 关于收费、价格、平台支持范围、具体性能效果等事实,资料中暂未提供。