sabahattink/codediag
GitHub: sabahattink/codediag
codediag 是一个零配置的 Node.js/NestJS 项目健康度扫描器,通过一条命令从 API 质量、安全性、依赖、测试和结构五个维度给出综合评分。
Stars: 2 | Forks: 0
codediag
在发布之前诊断你的代码。
一条命令。五个分析器。一个评分。
## 安装 ``` npx codediag scan . ``` 就这样。配置是可选的。不需要账户或服务器。 或者全局安装: ``` npm install -g codediag ``` ## 检查内容 codediag 会自动检测你的技术栈并运行 5 个分析器: ### API 健康度 `NestJS` 使用真正的 AST 分析(ts-morph,而不是正则表达式)从 `@Get`、`@Post`、`@Put`、`@Delete`、`@Patch` 装饰器中发现 endpoint。检查 auth guard、类型化的 DTO、Swagger 文档和返回类型。 ### 安全性 扫描硬编码的密钥(API key、Stripe key、AWS 凭证、GitHub token),验证 `.gitignore`,检查 helmet 中间件、CORS 配置、速率限制和密码哈希。 ### 依赖项 运行 `npm audit`,检查 lock 文件是否存在,标记已弃用的包,验证 engine 规范和基本的 npm 脚本。 ### 测试 检测测试文件和框架(Jest、Vitest、Mocha、Ava),计算测试与源代码的比例,检查 e2e 目录和覆盖率配置。 ### 结构 验证 README 质量、linter/formatter 配置、TypeScript 严格模式、NestJS 模块组织以及 `.env.example` 的存在。 ## 评分 每个分析器的评分为 0-100。加权平均值决定最终等级: ``` API Health: 25% · Security: 30% · Dependencies: 20% · Testing: 15% · Structure: 10% ``` | A+ | A | B+ | B | C | D | F | |:--:|:-:|:--:|:-:|:-:|:-:|:-:| | 95+ | 90+ | 85+ | 80+ | 70+ | 60+ | <60 | ## CLI ``` codediag scan . # Full report codediag scan . --format json # JSON (for CI/CD) codediag scan . --format md # Markdown (for PRs) codediag scan . --ci # JSON output + exit code codediag scan . --threshold 80 # Exit 1 below 80 in any output mode codediag scan . --quiet # Score only codediag scan . --verbose # All issues codediag init # Create .codediag.yml ``` ## CI/CD ``` # GitHub Actions - run: npx codediag scan . --ci --threshold 80 ``` ``` # GitLab CI codediag: script: npx codediag scan . --ci --threshold 80 ``` ``` # Pre-push hook (husky) npx codediag scan . --quiet --threshold 70 ``` ## 配置 可选。创建 `.codediag.yml` 或运行 `codediag init`。命令行 `--threshold` 优先于配置的阈值。配置的 阈值在扫描该项目时会被强制执行。如果没有配置文件, 普通扫描仅提供信息参考;`--ci` 使用默认阈值 70。 ``` threshold: 70 ignore: [node_modules, dist, .git, coverage] analyzers: api: true security: true dependencies: true testing: true structure: true ``` 未知选项和无效值会导致扫描失败,而不是被静默 忽略。`ignore` 下的目录和 glob 条目会应用于 检查源文件的分析器。 ## 支持的技术栈 | 技术栈 | API 健康度 | 安全性 | 依赖 | 测试 | 结构 | |-------|:---------:|:--------:|:----:|:-------:|:---------:| | NestJS | ✅ | ✅ | ✅ | ✅ | ✅ | | Next.js | 🔜 | ✅ | ✅ | ✅ | ✅ | | Express | 🔜 | ✅ | ✅ | ✅ | ✅ | | Node.js | — | ✅ | ✅ | ✅ | ✅ | ## 对比 | | codediag | SonarQube | Snyk | ESLint | |---|:---:|:---:|:---:|:---:| | 零配置 | ✅ | ❌ | ❌ | ❌ | | 感知 NestJS | ✅ | ❌ | ❌ | ❌ | | 安全扫描 | ✅ | ✅ | ✅ | ❌ | | 依赖审计 | ✅ | ❌ | ✅ | ❌ | | 测试检查 | ✅ | ✅ | ❌ | ❌ | | 统一评分 | ✅ | ✅ | ❌ | ❌ | | 离线支持 | ✅ | ❌ | ❌ | ✅ | | 免费 | ✅ | 部分 | 部分 | ✅ | ## 路线图 CodeDiag 正在积极开发中。现有的分析器是作为基础检查提供的, 并非宣称已完全覆盖框架或安全检查。 ### 0.2 - 可靠的基础 - [x] NestJS API、安全性、依赖、测试和结构分析器 - [x] 验证 `.codediag.yml` 配置 - [x] 确定性的阈值退出行为 - [x] 当漏洞导致非零退出时,保留 npm audit 结果 - [x] 自动化回归测试 - [ ] npm 所有权迁移和 `0.2.0` 发布 ### 0.3 - 框架深度 - [ ] Next.js 分析器 - [ ] Express 分析器 - [ ] 特定于框架的测试夹具和集成测试 ### 0.4 - CI 分发 - [ ] SVG 徽章生成器 - [ ] 可重用的 GitHub Action - [ ] 机器可读的 schema 文档 ### 后续 - [ ] Web 仪表板 - [ ] VS Code 扩展 - [ ] 具有明确审查的 AI 修复建议 ## 许可证 MIT - [Sabahattin Kalkan](https://sabahattinkalkan.com)
如果 codediag 在你的用户之前发现了问题,请给它点个 ⭐
标签:GNU通用公共许可证, LNA, MITM代理, NestJS, Node.js, 云安全监控, 依赖审计, 安全扫描, 时序注入, 暗色界面, 自动化攻击, 静态分析