clang-tidyで命名規則のチェック(&自動修正)
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
- const系
- メソッド
ConstexprMethod
-
ConstexprFunction
* ClassMethod
VirtualMethod
PrivateMethod
ProtectedMethod
PublicMethod
Method
-
Function
*
- 関数
-
ConstexprFunction
* GlobalFunction
-
Function
*
-
- テンプレート引数(型)
TypeTemplateParameter
-
TemplateParameter
*
- テンプレート引数(型以外)
ValueTemplateParameter
-
TemplateParameter
*
- テンプレート引数(テンプレート)
TemplateTemplateParameter
-
TemplateParameter
*
- 非対応ぽい
MacroDefinition
PureFunction
PureMethod
TemplateUsing
Using
キャピタライズの種類
Author And Source
この問題について(clang-tidyで命名規則のチェック(&自動修正)), 我々は、より多くの情報をここで見つけました https://qiita.com/tenmyo/items/9753609385c7e4ff5222著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .