【问题标题】:clang-tidy linting ignore third party headersclang-tidy linting 忽略第三方标头
【发布时间】:2021-06-19 21:46:44
【问题描述】:

我使用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.

PS:

我也试过了:

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

【问题讨论】:

    标签: c++ clang clang-tidy


    【解决方案1】:

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

    【讨论】:

    • 我遇到了同样的问题,-isystem 没有解决。它仍然在系统标题上显示错误。知道为什么吗?
    • 不知道,不知道你的设置很难说
    • 这里是详细信息:stackoverflow.com/questions/69972577/… 如果你能看一下就太好了。我应该提供更多信息吗?
    猜你喜欢
    • 2020-07-20
    • 2018-10-25
    • 2018-03-20
    • 2022-07-12
    • 2020-04-08
    • 2020-12-30
    • 2019-10-01
    • 2016-05-17
    • 2020-07-26
    相关资源
    最近更新 更多