使用 Clang-Tidy 和 Clazy 分析代码
注意: Clang 静态分析器检查是 Clang-Tidy 的一部分。要使用这些检查,必须为 Clang 工具创建自定义配置,并为 Clang-Tidy 启用它们。
分析当前文件
运行 Clang-Tidy 或 Clazy 分析当前打开的文件:
- 选择编辑器工具栏上的
(Analyze File) ,然后选择工具:Clang-Tidy 或Clazy 。
- 选择Tools >C++ >Analyze Current File with Clang-Tidy 或Analyze Current File with Clazy 。
分析打开的项目
要运行 Clang-Tidy 或 Clazy 来分析一个打开的项目,请执行下列操作
- 选择Analyze >Clang-Tidy 或Clazy 。
- 选择要应用检查的文件。
- 选择Analyze 开始检查。
查看诊断
Clang-Tidy 或Clazy 视图显示问题:
Clang-Tidy 视图中的诊断。
注意: 如果在模式选择器中选择Debug 以打开Debug 模式,然后选择Clang-Tidy 或Clazy ,则必须选择 (Analyze Project) 按钮才能打开Files to Analyze 对话框。
双击问题可移动到问题出现在代码编辑器中的位置。
如果某个问题存在 fixit,您可以选择问题旁边的复选框来安排修复。选择Select Fixits 复选框可选择所有修复程序。要查看问题的状态,请将鼠标指针悬停在复选框旁边的图标上。
要查看标有 图标的问题的更多信息,请将鼠标指针悬停在该行上。
选择 按钮,自定义当前项目的诊断。
过滤诊断
过滤诊断:
- 选择
打开Filter Diagnostics 对话框。
- 选择要查看的诊断程序。
- 选择OK 。
要查看所有诊断,请选择Select All 。要查看具有修复程序的诊断程序,请选择Select All with Fixits 。
要隐藏所有诊断程序,请选择Clear Selection 。
要查看特定类型的诊断,请右键单击Diagnostics 中的条目,然后在上下文菜单中选择Filter for This Diagnostic Kind 。要隐藏该类诊断,请选择Filter out This Diagnostic Kind 。
禁止诊断
要抑制诊断结果,请在右键菜单中选择Suppress This Diagnostic 或Suppress This Diagnostic Inline 。
要查看项目的抑制列表并删除其中的诊断程序,请选择Projects >Project Settings >Clang Tools 。
禁用检查
要在全局或针对特定项目禁用特定类型的检查,请在右键菜单中选择Disable This Check 或Disable These Checks 。
从 YAML 文件加载诊断程序
除了运行工具收集诊断结果外,还可以选择 ,从使用
-export fixes
选项导出的YAML文件中加载诊断结果。
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.