1 //===--- ModernizeTidyModule.cpp - clang-tidy -----------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "../ClangTidy.h" 11 #include "../ClangTidyModule.h" 12 #include "../ClangTidyModuleRegistry.h" 13 #include "DeprecatedHeadersCheck.h" 14 #include "LoopConvertCheck.h" 15 #include "MakeUniqueCheck.h" 16 #include "PassByValueCheck.h" 17 #include "RawStringLiteralCheck.h" 18 #include "RedundantVoidArgCheck.h" 19 #include "ReplaceAutoPtrCheck.h" 20 #include "ShrinkToFitCheck.h" 21 #include "UseAutoCheck.h" 22 #include "UseDefaultCheck.h" 23 #include "UseNullptrCheck.h" 24 #include "UseOverrideCheck.h" 25 26 using namespace clang::ast_matchers; 27 28 namespace clang { 29 namespace tidy { 30 namespace modernize { 31 32 class ModernizeModule : public ClangTidyModule { 33 public: 34 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { 35 CheckFactories.registerCheck<DeprecatedHeadersCheck>( 36 "modernize-deprecated-headers"); 37 CheckFactories.registerCheck<LoopConvertCheck>("modernize-loop-convert"); 38 CheckFactories.registerCheck<MakeUniqueCheck>("modernize-make-unique"); 39 CheckFactories.registerCheck<PassByValueCheck>("modernize-pass-by-value"); 40 CheckFactories.registerCheck<RawStringLiteralCheck>( 41 "modernize-raw-string-literal"); 42 CheckFactories.registerCheck<RedundantVoidArgCheck>( 43 "modernize-redundant-void-arg"); 44 CheckFactories.registerCheck<ReplaceAutoPtrCheck>( 45 "modernize-replace-auto-ptr"); 46 CheckFactories.registerCheck<ShrinkToFitCheck>("modernize-shrink-to-fit"); 47 CheckFactories.registerCheck<UseAutoCheck>("modernize-use-auto"); 48 CheckFactories.registerCheck<UseDefaultCheck>("modernize-use-default"); 49 CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr"); 50 CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override"); 51 } 52 53 ClangTidyOptions getModuleOptions() override { 54 ClangTidyOptions Options; 55 auto &Opts = Options.CheckOptions; 56 // For types whose size in bytes is above this threshold, we prefer taking a 57 // const-reference than making a copy. 58 Opts["modernize-loop-convert.MaxCopySize"] = "16"; 59 60 Opts["modernize-loop-convert.MinConfidence"] = "reasonable"; 61 Opts["modernize-loop-convert.NamingStyle"] = "CamelCase"; 62 Opts["modernize-pass-by-value.IncludeStyle"] = "llvm"; // Also: "google". 63 Opts["modernize-replace-auto-ptr.IncludeStyle"] = "llvm"; // Also: "google". 64 65 // Comma-separated list of macros that behave like NULL. 66 Opts["modernize-use-nullptr.NullMacros"] = "NULL"; 67 return Options; 68 } 69 }; 70 71 // Register the ModernizeTidyModule using this statically initialized variable. 72 static ClangTidyModuleRegistry::Add<ModernizeModule> X("modernize-module", 73 "Add modernize checks."); 74 75 } // namespace modernize 76 77 // This anchor is used to force the linker to link in the generated object file 78 // and thus register the ModernizeModule. 79 volatile int ModernizeModuleAnchorSource = 0; 80 81 } // namespace tidy 82 } // namespace clang 83