关于 static-code-analysis
static-code-analysis 是关于静态代码分析的指南,面向希望在代码运行前发现缺陷、安全问题和风格违规的开发者。内容涉及多种分析配置及自动化实践。
主要功能
- 01ESLint 配置指导
- 02Python 代码检查
- 03预提交钩子设置
- 04SonarQube 集成指导
- 05安全扫描与 AST 分析
适用场景
- 01在 CI/CD 中运行代码检查
- 02设置提交前检查
- 03自动化代码审查和安全检测
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ aj-geddes/ useful-ai-prompts --skill static-code-analysis安装后在 Claude Code 中输入/static-code-analysis确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/custom-ast-analysis.mdeslint-configuration.mdpre-commit-hooks.mdpython-linting-pylint-mypy.mdsecurity-scanning.mdsonarqube-integration.mdscripts/security-checklist.sh详细介绍
静态代码分析
目录
概述
使用自动化工具分析代码,而无需执行代码,从而及早发现错误、安全问题和风格违规。
适用场景
- 强制执行编码规范
- 检测安全漏洞
- 预防错误
- 自动化代码审查
- CI/CD 流水线
- 提交前钩子
- 辅助重构
快速入门
最小可运行示例:
// .eslintrc.js
module.exports = {
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:security/recommended",
],
plugins: ["@typescript-eslint", "security", "import"],
rules: {
"no-console": ["warn", { allow: ["error", "warn"] }],
"no-unused-vars": "error",
"prefer-const": "error",
eqeqeq: ["error", "always"],
"no-eval": "error",
"security/detect-object-injection": "warn",
"security/detect-non-literal-regexp": "warn",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/explicit-function-return-type": "error",
"import/order": [
"error",
{
groups: [
"builtin",
"external",
"internal",
// ... (see reference guides for full implementation)
参考指南
references/ 目录中的详细实现:
| 指南 | 内容 |
|---|---|
| ESLint 配置 | ESLint 配置 |
| Python 代码检查(pylint + mypy) | Python 代码检查(pylint + mypy) |
| 提交前钩子 | 提交前钩子 |
| SonarQube 集成 | SonarQube 集成 |
| 自定义 AST 分析 | 自定义 AST 分析 |
| 安全扫描 | 安全扫描 |
最佳实践
✅ 应该做
- 在 CI/CD 中运行代码检查工具
- 使用提交前钩子
- 配置 IDE 集成
- 逐步修复问题
- 记录自定义规则
- 在团队中共享配置
- 自动执行安全扫描
❌ 不应该做
- 忽略所有警告
- 跳过代码检查工具的设置
- 提交违反代码规范的内容
- 一开始就使用过于严格的规则
- 跳过安全扫描
- 无故禁用规则
评论
支持 Markdown