with one click
cpp-clang-tidy
Clang-Tidy 静态分析技能:使用 clang-tidy 进行 C/C++ 代码质量检测,支持自定义检查规则和自动修复
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Clang-Tidy 静态分析技能:使用 clang-tidy 进行 C/C++ 代码质量检测,支持自定义检查规则和自动修复
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
AI记忆持久化系统。使用memrec存储、检索、管理跨会话记忆。支持项目隔离、混合检索(KNN+BM25)、MMR重排、中文搜索。触发场景:(1)重要决策需记录,(2)关键知识需保存,(3)项目上下文需跨会话保持,(4)用户偏好需记忆,(5)检索历史知识辅助当前任务。
Rust 性能分析技能:通过 cargo flamegraph 生成火焰图(SVG),定位 CPU 热点函数并量化占比。适用于 Rust 项目性能瓶颈定位、热点分析、优化验证。触发场景:(1)分析 Rust 代码性能瓶颈,(2)定位 CPU 热点函数,(3)量化函数调用占比,(4)优化前后对比验证,(5)bench/unittest 性能不达预期时根因分析。
读取所有源代码,解构为设计图、设计文档、数据库设计; 没有执行文件,请按流程执行
项目问题侦测技能:综合分析设计、性能、安全问题,评分并提出重构或重建方案
局部代码修改技能:最小化修改完成功能,确保无蝴蝶效应,支持独立测试验证和全量关联检查
该skill没有执行文件,为操作指引:如何重构
| name | cpp-clang-tidy |
| description | Clang-Tidy 静态分析技能:使用 clang-tidy 进行 C/C++ 代码质量检测,支持自定义检查规则和自动修复 |
CLANG_TIDY=/usr/bin/clang-tidy
# 版本: Debian LLVM 19.1.7
需要 compile_commands.json 编译数据库:
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B build # CMake
bear -- make # 非 CMake (bear)
compiledb make # 非 CMake (compiledb)
SRC_DIR=src
COMPILE_DB=build
clang-tidy src/main.cpp -- -Iinclude # 单文件
clang-tidy -p $COMPILE_DB src/main.cpp # 使用编译数据库
run-clang-tidy -p $COMPILE_DB # 批量检查(推荐)
find $SRC_DIR -name '*.cpp' -o -name '*.c' | \
xargs clang-tidy -p $COMPILE_DB # 手动批量
clang-tidy --fix src/main.cpp -- -Iinclude # 自动修复
clang-tidy --fix-errors src/main.cpp -- -Iinclude # 修复含 error
find $SRC_DIR -name '*.cpp' | \
xargs -I{} clang-tidy --fix-errors {} -p $COMPILE_DB # 批量修复
clang-tidy src/main.cpp -- -Iinclude # 文本(默认)
clang-tidy --format-style=json src/main.cpp -- -Iinclude # JSON
clang-tidy --export-fixes=tidy-fixes.yaml src/main.cpp # YAML 修复建议
clang-tidy --checks='bugprone-*,security-*' src/main.cpp # 仅安全和 bugprone
clang-tidy --checks='*,-readability-*,-llvm-*' src/main.cpp # 排除特定规则
| 类别 | 前缀 | 描述 |
|---|---|---|
| 正确性 | clang-diagnostic-* / clang-analyzer-* | 编译器警告、静态分析 |
| 现代 C++ | modernize-* | 现代 C++ 用法建议 |
| 性能 | performance-* | 性能优化 |
| 可读性 | readability-* | 代码可读性 |
| 安全 | bugprone-* / security-* | 常见错误、安全漏洞 |
| 并发 | concurrency-* | 死锁、竞态条件 |
| 规范 | cert-* / misra-* / google-* | CERT/MISRA/Google 规范 |
templates/dot-clang-tidy.yaml → 复制到项目根目录为 .clang-tidytemplates/ci-github-actions.yamltemplates/cmake-integration.cmaketemplates/Makefile-tidy# 统计问题类型
clang-tidy --format-style=json src/main.cpp -- -Iinclude | \
jq -r '.[].DiagnosticName' | sort | uniq -c | sort -nr
# 提取高危问题
clang-tidy src/main.cpp -- -Iinclude 2>&1 | grep -E '(error|warning):'
输出报告模板:templates/report.md
| 特性 | Clang-Tidy | Cppcheck |
|---|---|---|
| 分析引擎 | Clang AST | 自定义解析器 |
| 编译数据库 | 必需 | 可选 |
| 自动修复 | 支持 | 不支持 |
| 检查规则数 | 500+ | 200+ |
| 分析速度 | 较慢 | 快 |
compile_commands.json 确保精度.clang-tidy 统一规范bugprone-*,performance-*,modernize-* 开始--fix 优先处理可自动修复项,修复后务必编译验证-I 参数run-clang-tidy -j N 并行// NOLINT 或 .clang-tidy 抑制--fix 可能不完整,修复后需编译验证技能版本: 1.0.0 | 工具版本: Clang-Tidy 19.1.7 | 适用: C/C++ (需 compile_commands.json)