哪些 clang-tidy 检查提供自动修复?

Which clang-tidy checks provide automated fixes?

我想找出哪些 clang-tidy 检查可以 运行 使用 -fix 选项,即自动生成固定代码。 我知道所有的 modernize-* 检查都可以做到这一点,其他一些检查也可以(比如 google-readability-casting),但我没有找到完整的列表。 某处有清单吗?或者除了阅读每张支票的来源之外还有其他方法可以找出答案?

编辑: 自 clang-tidy 10 起,修复选项包含在 documentation.

的检查列表中

我的其余回答对版本 9 及更低版本仍然有效。


grep --include=\*.cpp -rc './' -e "FixItHint"|grep -v ':0$' > FixItChecks.txt

我运行这个grep命令在clang-tidy源目录下。它计算所有 .cpp 文件中“FixItHint”字符串的出现次数,并过滤掉出现次数为零的文件。

clang::FixItHint 是一个 class(根据文档):

Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the problem.

我承认获取列表的方法有些粗糙,但是我检查了多个文件,结果似乎是正确的。

经过清理和排序的检查列表,其中包含修复:

abseil/StringFindStartswithCheck
android/CloexecCheck
boost/UseToStringCheck
bugprone/ArgumentCommentCheck
bugprone/BoolPointerImplicitConversionCheck
bugprone/CopyConstructorInitCheck
bugprone/InaccurateEraseCheck
bugprone/MacroParenthesesCheck
bugprone/MisplacedOperatorInStrlenInAllocCheck
bugprone/MoveForwardingReferenceCheck
bugprone/ParentVirtualCallCheck
bugprone/StringIntegerAssignmentCheck
bugprone/SuspiciousMemsetUsageCheck
bugprone/SuspiciousSemicolonCheck
bugprone/SuspiciousStringCompareCheck
bugprone/UnusedRaiiCheck
bugprone/VirtualNearMissCheck
cert/PostfixOperatorCheck
cppcoreguidelines/ProBoundsConstantArrayIndexCheck
cppcoreguidelines/ProTypeCstyleCastCheck
cppcoreguidelines/ProTypeMemberInitCheck
cppcoreguidelines/ProTypeStaticCastDowncastCheck
fuchsia/DefaultArgumentsCheck
fuchsia/RestrictSystemIncludesCheck
google/AvoidCStyleCastsCheck
google/ExplicitConstructorCheck
google/ExplicitMakePairCheck
google/GlobalVariableDeclarationCheck
google/TodoCommentCheck
llvm/IncludeOrderCheck
llvm/TwineLocalCheck
misc/DefinitionsInHeadersCheck
misc/RedundantExpressionCheck
misc/StaticAssertCheck
misc/UniqueptrResetReleaseCheck
misc/UnusedAliasDeclsCheck
misc/UnusedParametersCheck
misc/UnusedUsingDeclsCheck
modernize/AvoidBindCheck
modernize/DeprecatedHeadersCheck
modernize/LoopConvertCheck
modernize/MakeSmartPtrCheck
modernize/PassByValueCheck
modernize/RawStringLiteralCheck
modernize/RedundantVoidArgCheck
modernize/ReplaceAutoPtrCheck
modernize/ReplaceRandomShuffleCheck
modernize/ReturnBracedInitListCheck
modernize/ShrinkToFitCheck
modernize/UnaryStaticAssertCheck
modernize/UseAutoCheck
modernize/UseBoolLiteralsCheck
modernize/UseDefaultMemberInitCheck
modernize/UseEmplaceCheck
modernize/UseEqualsDefaultCheck
modernize/UseEqualsDeleteCheck
modernize/UseNoexceptCheck
modernize/UseNullptrCheck
modernize/UseOverrideCheck
modernize/UseTransparentFunctorsCheck
modernize/UseUncaughtExceptionsCheck
modernize/UseUsingCheck
objc/PropertyDeclarationCheck
performance/FasterStringFindCheck
performance/ForRangeCopyCheck
performance/InefficientAlgorithmCheck
performance/InefficientVectorOperationCheck
performance/MoveConstArgCheck
performance/TypePromotionInMathFnCheck
performance/UnnecessaryCopyInitialization
performance/UnnecessaryValueParamCheck
readability/AvoidConstParamsInDecls
readability/BracesAroundStatementsCheck
readability/ContainerSizeEmptyCheck
readability/DeleteNullPointerCheck
readability/IdentifierNamingCheck
readability/ImplicitBoolConversionCheck
readability/InconsistentDeclarationParameterNameCheck
readability/MisplacedArrayIndexCheck
readability/NamedParameterCheck
readability/NamespaceCommentCheck
readability/NonConstParameterCheck
readability/RedundantControlFlowCheck
readability/RedundantDeclarationCheck
readability/RedundantFunctionPtrDereferenceCheck
readability/RedundantMemberInitCheck
readability/RedundantSmartptrGetCheck
readability/RedundantStringCStrCheck
readability/RedundantStringInitCheck
readability/SimplifyBooleanExprCheck
readability/SimplifySubscriptExprCheck
readability/StaticAccessedThroughInstanceCheck
readability/StaticDefinitionInAnonymousNamespaceCheck
readability/StringCompareCheck
readability/UniqueptrDeleteReleaseCheck