内联方式禁用lang整洁检查 [英] Inline way to disable clang-tidy checks
问题描述
我正在尝试为一个项目设置clang-tidy。我希望能够获得干净的输出,并鼓励在可能的情况下使用-fix模式。但是,在个别情况下需要例外。
I'm trying to set up clang-tidy for a project. I'd like to be able to have clean output, and encourage the use of -fix mode where possible. However, there are individual cases where an exception is needed.
可以使用的尽可能多的
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreserved-id-macro"
// Code that is being specially exempted
#pragma clang diagnostic pop
对于等价的情况,如果要在本地禁用编译器警告,是否可以做点什么
for the equivalent case where one wants to locally disable a compiler warning, is it possible to do something similar from clang-tidy?
我尝试过
#pragma clang diagnostic push
#pragma clang diagnostic ignored "readability-identifier-naming"
// Code that is being specially exempted
#pragma clang diagnostic pop
,还用 clang
替换为 clang-tidy
。不幸的是,当使用 clang
作为编译目标并使用常规clang进行编译时,我收到编译警告
and also with clang
replaced with clang-tidy
. Unfortunately when using clang
as the pragma target and compiling with regular clang, I get the compilation warning
warning: pragma diagnostic expected option name (e.g. "-Wundef") [-Wunknown-pragmas]
和
warning: unknown pragma ignored [clang-diagnostic-unknown-pragmas]
在编译时是否使用 clang-tidy
代替 clang
。在源上运行时,都不会影响 clang-tidy
本身的输出。
when compiling if I use clang-tidy
in place of clang
. Neither make an impact on what clang-tidy
itself outputs when run over the source.
这是<$在x86_64 Linux上为c $ c> clang 和 clang-tidy
3.8。
推荐答案
只需在要clang-tidy忽略的行上的任何位置添加包含字符串NOLINT的注释。例如:
Just add a comment containing the string NOLINT anywhere on the line you want clang-tidy to ignore. For example:
badcode; // NOLINT
// NOLINTNEXTLINE
badcode;
badcode; // NOLINT(cert-err-58-cpp)
请参见文档此处。
这篇关于内联方式禁用lang整洁检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!