clang-tidy 可读性标识符命名 IgnoredRegexp

clang-tidy readability-identifier-naming IgnoredRegexp

我想从 readability-identifier-naming.

的 linting 中排除某些正则表达式模式

部分.clang-tidy我正在使用:

Checks: 'readability-*'
CheckOptions:
  - key:             readability-identifier-naming.TypeAliasCase
    value:           CamelCase
  - key:             readability-identifier-naming.TypeAliasIgnoredRegexp
    value:           '(*_type|*reference|*iterator)'
  - key:             readability-identifier-naming.TypedefCase
    value:           CamelCase
  - key:             readability-identifier-naming.TypedefIgnoredRegexp
    value:           '(*_type|*reference|*iterator)'

但是,不会抑制对这些正则表达式模式的警告。

例如,

using value_type = T;
using reference = value_type&;
using const_iterator = const T*;

这是为 clang-tidy 使用正则表达式的正确方法吗?

查看引入 IgnoredRegexpchangeset 看来您必须使用正确的正则表达式 - 而不是 value-string

中的全局匹配
%check_clang_tidy %s readability-identifier-naming %t -- 
  -config='{CheckOptions: [ 
    {key: readability-identifier-naming.ParameterCase, value: CamelCase}, 
    {key: readability-identifier-naming.ParameterIgnoredRegexp, value: "^[a-z]{1,2}$"}, 
    {key: readability-identifier-naming.ClassCase, value: CamelCase}, 
    {key: readability-identifier-naming.ClassIgnoredRegexp, value: "^fo$|^fooo$"}, 
    {key: readability-identifier-naming.StructCase, value: CamelCase}, 
    {key: readability-identifier-naming.StructIgnoredRegexp, value: "sooo|so|soo|$invalidregex["} 
 ]}'

参见:clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-ignored-regexp.cpp

根据您的问题和示例进行猜测,模式可能如下所示:

value:           '^.*_type$|^.*reference$|^.*iterator$'

如果你需要一个非贪婪的版本,你可能就不走运了,因为杠杆 llvm::Regex class 使用 POSIX ERE,我猜不支持惰性匹配:

value:           '^.*?_type$|^.*?reference$|^.*?iterator$'