c++ - clang-tidy 可读性标识符命名 IgnoredRegexp
问题描述
我想从 linting for 中排除某些正则表达式模式readability-identifier-naming
。
.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
吗?
解决方案
查看引入的变更集IgnoredRegexp
,您似乎必须使用正确的正则表达式 - 而不是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
类使用的是 POSIX ERE,我猜不支持惰性匹配:
value: '^.*?_type$|^.*?reference$|^.*?iterator$'
推荐阅读
- apostrophe-cms - ApostropheCMS - 从用户组来宾中删除页面菜单
- javascript - 从会话存储中打开折叠
- javascript - Wordpress admin-ajax.php 加载失败
- android - kotlin中的getParcelable无法正确解析Android对象模型
- caching - 如何在 Web 开发时可靠地清除 Safari 12.0 中的缓存
- ios - touchesBegan 时 UIBarButtonItem 的扩展
- xml - 为什么我的缩进设置在 Powershell 的 XmlWriter 中被忽略?
- spring-boot - 获取请求未通过授权标头
- java - 如何知道当前触发了哪个测试
- android - android firebase 更新列表消息