clang-tidy
、C/C++のプログラミングでは、とても便利な静的解析ツールです。
-fix
や-fix-errors
オプションをつけて実行すれば、ある程度自動修正してくれる賢さも嬉しいです。
命名規則のチェックや、自動修正に対応していることに気づいたので紹介します。
種類ごとにキャピタライズ(CamelCase,lower_case)や、プレフィクス/サフィックスルールを決められます。
いちおうドキュメントもありますが、指定できるオプションは記載されていませんでした。テストを直接見るのが確実です。
clang-tidy
は、.clang-tidy
ファイルに設定を書いておくと、デフォルトでそれを使ってくれます。
個別の設定をいちいち引数で指定するのは面倒なので、設定ファイルにまとめて書いておくのがおすすめです。
.clang-tidy
Checks: 'readability-identifier-naming'
HeaderFilterRegex: '.*'
CheckOptions:
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.FunctionCase
value: camelBack
- key: readability-identifier-naming.MemberCase
value: lower_case
- key: readability-identifier-naming.MemberSuffix
value: _
- key: readability-identifier-naming.ParameterCase
value: lower_case
- key: readability-identifier-naming.UnionCase
value: CamelCase
- key: readability-identifier-naming.VariableCase
value: lower_case
参考メモ
ソースコードより。
対象の種類
複数に当てはまる場合、上のが優先されます。*は複数ヶ所に反映されるもの。なかなか混沌としています。
Typedef
TypeAlias
- 名前空間
InlineNamespace
Namespace
-
Enum
* - Enum定数
EnumConstant
-
Constant
* - クラス系
AbstractClass
Struct
Class
Union
-
Enum
* - メンバ
ConstantMember
-
Constant
* PrivateMember
ProtectedMember
PublicMember
Member
- 引数
-
ConstexprVariable
* ConstantParameter
-
Constant
* ParameterPack
Parameter
- 変数
- const系
-
ConstexprVariable
* ClassConstant
GlobalConstant
StaticConstant
LocalConstant
-
Constant
*
-
ClassMember
GlobalVariable
StaticVariable
LocalVariable
Variable
- メソッド
ConstexprMethod
-
ConstexprFunction
* ClassMethod
VirtualMethod
PrivateMethod
ProtectedMethod
PublicMethod
Method
-
Function
* - 関数
-
ConstexprFunction
* GlobalFunction
-
Function
* - テンプレート引数(型)
TypeTemplateParameter
-
TemplateParameter
* - テンプレート引数(型以外)
ValueTemplateParameter
-
TemplateParameter
* - テンプレート引数(テンプレート)
TemplateTemplateParameter
-
TemplateParameter
* - 非対応ぽい
MacroDefinition
PureFunction
PureMethod
TemplateUsing
Using
キャピタライズの種類
- aNy_CasE
- lower_case
- UPPER_CASE
- camelBack
- CamelCase
- Camel_Snake_Case(アップデートで追加?1)
- camel_Snake_Back(アップデートで追加?1)