微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

clang-tidy linting 忽略第三方标头

如何解决clang-tidy linting 忽略第三方标头

我使用 clang-tidy 来整理项目代码。该项目使用第三方标头,例如来自 cmake 生成的 protobuf 文件,如 logger.pb.h。我只想 lint 项目特定的源文件,并希望将第三方标头作为系统标头处理,因此我使用 -isystem

我的项目树看起来像:

source
└── logger.cpp

dependencies
└── include
    ├── logger.pb.h
    └── queue.h

由于我使用动态脚本,因此我使用 .clang-tidy 配置文件进行了混合,我称之为

clang-tidy -export-fixes=fixes.txt /path/to/logger.cpp -- -isystem /path/to/dependencies/include

使用配置文件 .clang-tidy

Checks: '-*,clang-diagnostic-*,clang-analyzer-*,readability-identifier-naming'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
FormatStyle:     none
CheckOptions:
  - { key: readability-identifier-naming.AbstractClassCase,value: CamelCase  }
  - { key: readability-identifier-naming.AbstractClassprefix,value: Abstrac    }
... more keys ...

clang-tidy 按预期在我的源文件 logger.cpp显示错误。但它也抱怨我使用的第三方标头,我不知道如何摆脱:

path/to/dependencies/include/logger.pb.h:263:57: warning: invalid case style for private member '_cached_size_' [readability-identifier-naming]
  mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
                                                        ^~~~~~~~~~~~~
                                                        _cachedSize

path/to/source/logger.cpp:26:11: warning: invalid case style for local pointer 'MyVar' [readability-identifier-naming]
    char *MyVar;
          ^~~~~
          myVar

Suppressed 24721 warnings (24717 in non-user code,4 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

附注:

我也试过:

-I /path/to/dependencies/include
-isystem=/path/to/dependencies/include

解决方法

最后我使用了 -isystem /path/to/dependencies/include 并且它起作用了。我不知道为什么它以前不起作用。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。