1 //===--- ModernizeTidyModule.cpp - clang-tidy -----------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "../ClangTidy.h" 10 #include "../ClangTidyModule.h" 11 #include "../ClangTidyModuleRegistry.h" 12 #include "AvoidBindCheck.h" 13 #include "AvoidCArraysCheck.h" 14 #include "ConcatNestedNamespacesCheck.h" 15 #include "DeprecatedHeadersCheck.h" 16 #include "DeprecatedIosBaseAliasesCheck.h" 17 #include "LoopConvertCheck.h" 18 #include "MakeSharedCheck.h" 19 #include "MakeUniqueCheck.h" 20 #include "PassByValueCheck.h" 21 #include "RawStringLiteralCheck.h" 22 #include "RedundantVoidArgCheck.h" 23 #include "ReplaceAutoPtrCheck.h" 24 #include "ReplaceDisallowCopyAndAssignMacroCheck.h" 25 #include "ReplaceRandomShuffleCheck.h" 26 #include "ReturnBracedInitListCheck.h" 27 #include "ShrinkToFitCheck.h" 28 #include "UnaryStaticAssertCheck.h" 29 #include "UseAutoCheck.h" 30 #include "UseBoolLiteralsCheck.h" 31 #include "UseDefaultMemberInitCheck.h" 32 #include "UseEmplaceCheck.h" 33 #include "UseEqualsDefaultCheck.h" 34 #include "UseEqualsDeleteCheck.h" 35 #include "UseNodiscardCheck.h" 36 #include "UseNoexceptCheck.h" 37 #include "UseNullptrCheck.h" 38 #include "UseOverrideCheck.h" 39 #include "UseTrailingReturnTypeCheck.h" 40 #include "UseTransparentFunctorsCheck.h" 41 #include "UseUncaughtExceptionsCheck.h" 42 #include "UseUsingCheck.h" 43 44 using namespace clang::ast_matchers; 45 46 namespace clang { 47 namespace tidy { 48 namespace modernize { 49 50 class ModernizeModule : public ClangTidyModule { 51 public: addCheckFactories(ClangTidyCheckFactories & CheckFactories)52 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { 53 CheckFactories.registerCheck<AvoidBindCheck>("modernize-avoid-bind"); 54 CheckFactories.registerCheck<AvoidCArraysCheck>("modernize-avoid-c-arrays"); 55 CheckFactories.registerCheck<ConcatNestedNamespacesCheck>( 56 "modernize-concat-nested-namespaces"); 57 CheckFactories.registerCheck<DeprecatedHeadersCheck>( 58 "modernize-deprecated-headers"); 59 CheckFactories.registerCheck<DeprecatedIosBaseAliasesCheck>( 60 "modernize-deprecated-ios-base-aliases"); 61 CheckFactories.registerCheck<LoopConvertCheck>("modernize-loop-convert"); 62 CheckFactories.registerCheck<MakeSharedCheck>("modernize-make-shared"); 63 CheckFactories.registerCheck<MakeUniqueCheck>("modernize-make-unique"); 64 CheckFactories.registerCheck<PassByValueCheck>("modernize-pass-by-value"); 65 CheckFactories.registerCheck<RawStringLiteralCheck>( 66 "modernize-raw-string-literal"); 67 CheckFactories.registerCheck<RedundantVoidArgCheck>( 68 "modernize-redundant-void-arg"); 69 CheckFactories.registerCheck<ReplaceAutoPtrCheck>( 70 "modernize-replace-auto-ptr"); 71 CheckFactories.registerCheck<ReplaceDisallowCopyAndAssignMacroCheck>( 72 "modernize-replace-disallow-copy-and-assign-macro"); 73 CheckFactories.registerCheck<ReplaceRandomShuffleCheck>( 74 "modernize-replace-random-shuffle"); 75 CheckFactories.registerCheck<ReturnBracedInitListCheck>( 76 "modernize-return-braced-init-list"); 77 CheckFactories.registerCheck<ShrinkToFitCheck>("modernize-shrink-to-fit"); 78 CheckFactories.registerCheck<UnaryStaticAssertCheck>( 79 "modernize-unary-static-assert"); 80 CheckFactories.registerCheck<UseAutoCheck>("modernize-use-auto"); 81 CheckFactories.registerCheck<UseBoolLiteralsCheck>( 82 "modernize-use-bool-literals"); 83 CheckFactories.registerCheck<UseDefaultMemberInitCheck>( 84 "modernize-use-default-member-init"); 85 CheckFactories.registerCheck<UseEmplaceCheck>("modernize-use-emplace"); 86 CheckFactories.registerCheck<UseEqualsDefaultCheck>("modernize-use-equals-default"); 87 CheckFactories.registerCheck<UseEqualsDeleteCheck>( 88 "modernize-use-equals-delete"); 89 CheckFactories.registerCheck<UseNodiscardCheck>( 90 "modernize-use-nodiscard"); 91 CheckFactories.registerCheck<UseNoexceptCheck>("modernize-use-noexcept"); 92 CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr"); 93 CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override"); 94 CheckFactories.registerCheck<UseTrailingReturnTypeCheck>( 95 "modernize-use-trailing-return-type"); 96 CheckFactories.registerCheck<UseTransparentFunctorsCheck>( 97 "modernize-use-transparent-functors"); 98 CheckFactories.registerCheck<UseUncaughtExceptionsCheck>( 99 "modernize-use-uncaught-exceptions"); 100 CheckFactories.registerCheck<UseUsingCheck>("modernize-use-using"); 101 } 102 getModuleOptions()103 ClangTidyOptions getModuleOptions() override { 104 ClangTidyOptions Options; 105 auto &Opts = Options.CheckOptions; 106 // For types whose size in bytes is above this threshold, we prefer taking a 107 // const-reference than making a copy. 108 Opts["modernize-loop-convert.MaxCopySize"] = "16"; 109 110 Opts["modernize-loop-convert.MinConfidence"] = "reasonable"; 111 Opts["modernize-loop-convert.NamingStyle"] = "CamelCase"; 112 Opts["modernize-pass-by-value.IncludeStyle"] = "llvm"; // Also: "google". 113 Opts["modernize-replace-auto-ptr.IncludeStyle"] = "llvm"; // Also: "google". 114 115 // Comma-separated list of macros that behave like NULL. 116 Opts["modernize-use-nullptr.NullMacros"] = "NULL"; 117 return Options; 118 } 119 }; 120 121 // Register the ModernizeTidyModule using this statically initialized variable. 122 static ClangTidyModuleRegistry::Add<ModernizeModule> X("modernize-module", 123 "Add modernize checks."); 124 125 } // namespace modernize 126 127 // This anchor is used to force the linker to link in the generated object file 128 // and thus register the ModernizeModule. 129 volatile int ModernizeModuleAnchorSource = 0; 130 131 } // namespace tidy 132 } // namespace clang 133