cpp-clang-tidy
Clang-Tidy 静态分析技能:使用 clang-tidy 进行 C/C++ 代码质量检测,支持自定义检查规则和自动修复
Skill by hellyguo
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/hellyguo-cpp-clang-tidy
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/cpp-clang-tidy
What's inside
- Skill name
cpp-clang-tidy- Description
- Clang-Tidy 静态分析技能:使用 clang-tidy 进行 C/C++ 代码质量检测,支持自定义检查规则和自动修复
- License
- Apache-2.0
- Instructions
- 123 lines in SKILL.md · view on GitHub
Files (6)
- SKILL.md
- Makefile-tidy · templates/
- ci-github-actions.yaml · templates/
- cmake-integration.cmake · templates/
- dot-clang-tidy.yaml · templates/
- report.md · templates/
SKILL.md (first lines)
# Clang-Tidy C/C++ 静态分析技能
> 本文件中的 `templates/...` 均指本技能目录下的 `templates/` 子目录。
## 工具位置
```bash
CLANG_TIDY=/usr/bin/clang-tidy
# 版本: Debian LLVM 19.1.7
```
## 前置条件
需要 `compile_commands.json` 编译数据库:
```bash
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B build # CMake
bear -- make # 非 CMake (bear)
compiledb make # 非 CMake (compiledb)
```
## 执行流程
### 步骤1:确定路径
```bash
SRC_DIR=src
COMPILE_DB=build
```
### 步骤2:执行分析
```bash
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 # 手动批量
```
### 步骤3:自动修复
```bash
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 # 批量修复
```
### 步骤4:输出格式
```bash
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 修复建议
```
### 步骤5:指定检查规则
```bash
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-tidy`
- CI 集成:`templates/ci-github-actions.yaml`
- CMake 集成:`templates/cmake-integration.cmake`
- Makefile 集成:`templates/Makefile-tidy`
## 分析结果处理
```bash
# 统计问题类型
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`
## 与 Cppcheck 对比
| 特性 | Clang-Tidy | Cppcheck |
| --- | --- | --- |
| 分析引擎 | Clang AST | 自定义解析器 |
| 编译数据库 | 必需 | 可选 |
| 自动修复 | 支持 | 不支持 |
| 检查规则数 | 500+ | 200+ |
| 分析速度 | 较慢 | 快 |
## 最佳实践
1. 使用 `compile_commands.json` 确保精度
2. 项目级 `.clang-tidy` 统一规范
3. 渐进式采用:从 `bugprone-*,performance-*,modernize-*` 开始
4. `--fix` 优先处理可自动修复项,修复后务必编译验证
5. CI 集成,定期更新
## 注意事项
- 无编译数据库时需手动指定 `-I` 参数
- 大型项目用 `run-clang-tidy -j N` 并行
- 误报用 `// NOLINT` 或 `.clang-tidy` 抑制From hellyguo/self-ai-spec, Apache-2.0.
More from hellyguo/self-ai-spec
- 0.618score
code-review
hellyguo
代码审查框架:通用审查流程 + 语言特定规则引用,支持多语言代码审查
SkillAFreshness: A★ 8Claude Code +9 - 0.614score
code-deconstruct
hellyguo
读取所有源代码,解构为设计图、设计文档、数据库设计; 没有执行文件,请按流程执行
SkillAFreshness: A★ 8Claude Code +9 - 0.592score
gdb-heap-analysis
hellyguo
GDB heap/arena memory analysis for core dump debugging.
SkillBFreshness: B★ 8Claude Code +9 - 0.589score
java-coverage
hellyguo
Strategies and patterns to boost test coverage to 80%+ line or 60%+ branch coverage.
SkillBFreshness: B★ 8Claude Code +9 - 0.581score
java-check-spotbugs
hellyguo
SpotBugs静态分析技能:使用SpotBugs、Find Security Bugs、fb-contrib进行Java代码缺陷和安全分析
SkillBFreshness: B★ 8Claude Code +9 - 0.581score
cpp-tscancode
hellyguo
TscanCode静态分析技能:使用TscanCode(腾讯开源)进行C/C++代码质量分析,检测缺陷、安全漏洞和代码风格问题
SkillBFreshness: B★ 8Claude Code +9 - 0.580score
ast-grep-block
hellyguo
基于 ast-grep 的代码审查门禁:使用 code-checklist 规则集对 Java/C++/ANSI C 项目分级扫描(high/medium/low),输出命中清单与 CI 退出码。仅使用 CLI 模式(run.sh),适用于交互式审查、CI 质量门禁、批量检测
SkillBFreshness: B★ 8Claude Code +9 - 0.578score
java-check-pmd
hellyguo
PMD静态分析技能:使用PMD进行Java代码质量分析,检测代码坏味道、编码规范和安全问题
SkillBFreshness: B★ 8Claude Code +9 - 0.578score
java-env
hellyguo
该skill没有执行文件,为信息输入:Java开发需要的环境信息
SkillBFreshness: B★ 8Claude Code +9 - 0.575score
code-refactor
hellyguo
该skill没有执行文件,为操作指引:如何重构
SkillBFreshness: B★ 8Claude Code +9 - 0.575score
java-asprof
hellyguo
该skill没有执行文件,为操作指引:采集Java执行情况
SkillBFreshness: B★ 8Claude Code +9 - 0.574score
code-part-modification
hellyguo
局部代码修改技能:最小化修改完成功能,确保无蝴蝶效应,支持独立测试验证和全量关联检查
SkillBFreshness: B★ 8Claude Code +9
Signals
- Stars
- 8
- Forks
- 0
- Open issues
- 0
- Last commit (this folder)
- Jul 16, 2026 (3 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- Apache-2.0
- Repository
- github.com/hellyguo/self-ai-spec
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from hellyguo
- 0.618score
code-review
hellyguo
代码审查框架:通用审查流程 + 语言特定规则引用,支持多语言代码审查
SkillAFreshness: A★ 8Claude Code +9 - 0.614score
code-deconstruct
hellyguo
读取所有源代码,解构为设计图、设计文档、数据库设计; 没有执行文件,请按流程执行
SkillAFreshness: A★ 8Claude Code +9 - 0.592score
gdb-heap-analysis
hellyguo
GDB heap/arena memory analysis for core dump debugging.
SkillBFreshness: B★ 8Claude Code +9 - 0.589score
java-coverage
hellyguo
Strategies and patterns to boost test coverage to 80%+ line or 60%+ branch coverage.
SkillBFreshness: B★ 8Claude Code +9 - 0.581score
cpp-tscancode
hellyguo
TscanCode静态分析技能:使用TscanCode(腾讯开源)进行C/C++代码质量分析,检测缺陷、安全漏洞和代码风格问题
SkillBFreshness: B★ 8Claude Code +9 - 0.581score
java-check-spotbugs
hellyguo
SpotBugs静态分析技能:使用SpotBugs、Find Security Bugs、fb-contrib进行Java代码缺陷和安全分析
SkillBFreshness: B★ 8Claude Code +9
Cite this page
cpp-clang-tidy skill. Agent Mart. https://agentmart.dev/skills/hellyguo-cpp-clang-tidy (last updated 2026-10-24)