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 "MacroToEnumCheck.h" 19 #include "MakeSharedCheck.h" 20 #include "MakeUniqueCheck.h" 21 #include "PassByValueCheck.h" 22 #include "RawStringLiteralCheck.h" 23 #include "RedundantVoidArgCheck.h" 24 #include "ReplaceAutoPtrCheck.h" 25 #include "ReplaceDisallowCopyAndAssignMacroCheck.h" 26 #include "ReplaceRandomShuffleCheck.h" 27 #include "ReturnBracedInitListCheck.h" 28 #include "ShrinkToFitCheck.h" 29 #include "UnaryStaticAssertCheck.h" 30 #include "UseAutoCheck.h" 31 #include "UseBoolLiteralsCheck.h" 32 #include "UseDefaultMemberInitCheck.h" 33 #include "UseEmplaceCheck.h" 34 #include "UseEqualsDefaultCheck.h" 35 #include "UseEqualsDeleteCheck.h" 36 #include "UseNodiscardCheck.h" 37 #include "UseNoexceptCheck.h" 38 #include "UseNullptrCheck.h" 39 #include "UseOverrideCheck.h" 40 #include "UseTrailingReturnTypeCheck.h" 41 #include "UseTransparentFunctorsCheck.h" 42 #include "UseUncaughtExceptionsCheck.h" 43 #include "UseUsingCheck.h" 44 45 using namespace clang::ast_matchers; 46 47 namespace clang::tidy { 48 namespace modernize { 49 50 class ModernizeModule : public ClangTidyModule { 51 public: 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<MacroToEnumCheck>("modernize-macro-to-enum"); 63 CheckFactories.registerCheck<MakeSharedCheck>("modernize-make-shared"); 64 CheckFactories.registerCheck<MakeUniqueCheck>("modernize-make-unique"); 65 CheckFactories.registerCheck<PassByValueCheck>("modernize-pass-by-value"); 66 CheckFactories.registerCheck<RawStringLiteralCheck>( 67 "modernize-raw-string-literal"); 68 CheckFactories.registerCheck<RedundantVoidArgCheck>( 69 "modernize-redundant-void-arg"); 70 CheckFactories.registerCheck<ReplaceAutoPtrCheck>( 71 "modernize-replace-auto-ptr"); 72 CheckFactories.registerCheck<ReplaceDisallowCopyAndAssignMacroCheck>( 73 "modernize-replace-disallow-copy-and-assign-macro"); 74 CheckFactories.registerCheck<ReplaceRandomShuffleCheck>( 75 "modernize-replace-random-shuffle"); 76 CheckFactories.registerCheck<ReturnBracedInitListCheck>( 77 "modernize-return-braced-init-list"); 78 CheckFactories.registerCheck<ShrinkToFitCheck>("modernize-shrink-to-fit"); 79 CheckFactories.registerCheck<UnaryStaticAssertCheck>( 80 "modernize-unary-static-assert"); 81 CheckFactories.registerCheck<UseAutoCheck>("modernize-use-auto"); 82 CheckFactories.registerCheck<UseBoolLiteralsCheck>( 83 "modernize-use-bool-literals"); 84 CheckFactories.registerCheck<UseDefaultMemberInitCheck>( 85 "modernize-use-default-member-init"); 86 CheckFactories.registerCheck<UseEmplaceCheck>("modernize-use-emplace"); 87 CheckFactories.registerCheck<UseEqualsDefaultCheck>("modernize-use-equals-default"); 88 CheckFactories.registerCheck<UseEqualsDeleteCheck>( 89 "modernize-use-equals-delete"); 90 CheckFactories.registerCheck<UseNodiscardCheck>( 91 "modernize-use-nodiscard"); 92 CheckFactories.registerCheck<UseNoexceptCheck>("modernize-use-noexcept"); 93 CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr"); 94 CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override"); 95 CheckFactories.registerCheck<UseTrailingReturnTypeCheck>( 96 "modernize-use-trailing-return-type"); 97 CheckFactories.registerCheck<UseTransparentFunctorsCheck>( 98 "modernize-use-transparent-functors"); 99 CheckFactories.registerCheck<UseUncaughtExceptionsCheck>( 100 "modernize-use-uncaught-exceptions"); 101 CheckFactories.registerCheck<UseUsingCheck>("modernize-use-using"); 102 } 103 104 ClangTidyOptions getModuleOptions() override { 105 ClangTidyOptions Options; 106 auto &Opts = Options.CheckOptions; 107 // For types whose size in bytes is above this threshold, we prefer taking a 108 // const-reference than making a copy. 109 Opts["modernize-loop-convert.MaxCopySize"] = "16"; 110 111 Opts["modernize-loop-convert.MinConfidence"] = "reasonable"; 112 Opts["modernize-loop-convert.NamingStyle"] = "CamelCase"; 113 Opts["modernize-pass-by-value.IncludeStyle"] = "llvm"; // Also: "google". 114 Opts["modernize-replace-auto-ptr.IncludeStyle"] = "llvm"; // Also: "google". 115 116 // Comma-separated list of macros that behave like NULL. 117 Opts["modernize-use-nullptr.NullMacros"] = "NULL"; 118 return Options; 119 } 120 }; 121 122 // Register the ModernizeTidyModule using this statically initialized variable. 123 static ClangTidyModuleRegistry::Add<ModernizeModule> X("modernize-module", 124 "Add modernize checks."); 125 126 } // namespace modernize 127 128 // This anchor is used to force the linker to link in the generated object file 129 // and thus register the ModernizeModule. 130 volatile int ModernizeModuleAnchorSource = 0; 131 132 } // namespace clang::tidy 133