1 //===--- GoogleTidyModule.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 "../readability/BracesAroundStatementsCheck.h" 14 #include "../readability/FunctionSizeCheck.h" 15 #include "../readability/NamespaceCommentCheck.h" 16 #include "../readability/RedundantSmartptrGetCheck.h" 17 #include "AvoidCStyleCastsCheck.h" 18 #include "DefaultArgumentsCheck.h" 19 #include "ExplicitConstructorCheck.h" 20 #include "ExplicitMakePairCheck.h" 21 #include "GlobalNamesInHeadersCheck.h" 22 #include "IntegerTypesCheck.h" 23 #include "MemsetZeroLengthCheck.h" 24 #include "NonConstReferences.h" 25 #include "OverloadedUnaryAndCheck.h" 26 #include "StringReferenceMemberCheck.h" 27 #include "TodoCommentCheck.h" 28 #include "UnnamedNamespaceInHeaderCheck.h" 29 #include "UsingNamespaceDirectiveCheck.h" 30 31 using namespace clang::ast_matchers; 32 33 namespace clang { 34 namespace tidy { 35 namespace google { 36 37 class GoogleModule : public ClangTidyModule { 38 public: 39 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { 40 CheckFactories.registerCheck<build::ExplicitMakePairCheck>( 41 "google-build-explicit-make-pair"); 42 CheckFactories.registerCheck<build::UnnamedNamespaceInHeaderCheck>( 43 "google-build-namespaces"); 44 CheckFactories.registerCheck<build::UsingNamespaceDirectiveCheck>( 45 "google-build-using-namespace"); 46 CheckFactories.registerCheck<DefaultArgumentsCheck>( 47 "google-default-arguments"); 48 CheckFactories.registerCheck<ExplicitConstructorCheck>( 49 "google-explicit-constructor"); 50 CheckFactories.registerCheck<runtime::IntegerTypesCheck>( 51 "google-runtime-int"); 52 CheckFactories.registerCheck<runtime::OverloadedUnaryAndCheck>( 53 "google-runtime-operator"); 54 CheckFactories.registerCheck<runtime::NonConstReferences>( 55 "google-runtime-references"); 56 CheckFactories.registerCheck<runtime::StringReferenceMemberCheck>( 57 "google-runtime-member-string-references"); 58 CheckFactories.registerCheck<runtime::MemsetZeroLengthCheck>( 59 "google-runtime-memset"); 60 CheckFactories.registerCheck<readability::AvoidCStyleCastsCheck>( 61 "google-readability-casting"); 62 CheckFactories.registerCheck<readability::TodoCommentCheck>( 63 "google-readability-todo"); 64 CheckFactories 65 .registerCheck<clang::tidy::readability::BracesAroundStatementsCheck>( 66 "google-readability-braces-around-statements"); 67 CheckFactories.registerCheck<readability::GlobalNamesInHeadersCheck>( 68 "google-global-names-in-headers"); 69 CheckFactories.registerCheck<clang::tidy::readability::FunctionSizeCheck>( 70 "google-readability-function-size"); 71 CheckFactories 72 .registerCheck<clang::tidy::readability::NamespaceCommentCheck>( 73 "google-readability-namespace-comments"); 74 CheckFactories 75 .registerCheck<clang::tidy::readability::RedundantSmartptrGetCheck>( 76 "google-readability-redundant-smartptr-get"); 77 } 78 79 ClangTidyOptions getModuleOptions() override { 80 ClangTidyOptions Options; 81 auto &Opts = Options.CheckOptions; 82 Opts["google-readability-braces-around-statements.ShortStatementLines"] = 83 "1"; 84 Opts["google-readability-function-size.StatementThreshold"] = "800"; 85 Opts["google-readability-namespace-comments.ShortNamespaceLines"] = "10"; 86 Opts["google-readability-namespace-comments.SpacesBeforeComments"] = "2"; 87 return Options; 88 } 89 }; 90 91 // Register the GoogleTidyModule using this statically initialized variable. 92 static ClangTidyModuleRegistry::Add<GoogleModule> X("google-module", 93 "Adds Google lint checks."); 94 95 } // namespace google 96 97 // This anchor is used to force the linker to link in the generated object file 98 // and thus register the GoogleModule. 99 volatile int GoogleModuleAnchorSource = 0; 100 101 } // namespace tidy 102 } // namespace clang 103