1 //===--- GoogleTidyModule.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 "../readability/BracesAroundStatementsCheck.h" 13 #include "../readability/FunctionSizeCheck.h" 14 #include "../readability/NamespaceCommentCheck.h" 15 #include "AvoidCStyleCastsCheck.h" 16 #include "AvoidThrowingObjCExceptionCheck.h" 17 #include "AvoidUnderscoreInGoogletestNameCheck.h" 18 #include "DefaultArgumentsCheck.h" 19 #include "ExplicitConstructorCheck.h" 20 #include "ExplicitMakePairCheck.h" 21 #include "FunctionNamingCheck.h" 22 #include "GlobalNamesInHeadersCheck.h" 23 #include "GlobalVariableDeclarationCheck.h" 24 #include "IntegerTypesCheck.h" 25 #include "NonConstReferences.h" 26 #include "OverloadedUnaryAndCheck.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<readability::GlobalNamesInHeadersCheck>( 51 "google-global-names-in-headers"); 52 CheckFactories.registerCheck<objc::AvoidThrowingObjCExceptionCheck>( 53 "google-objc-avoid-throwing-exception"); 54 CheckFactories.registerCheck<objc::FunctionNamingCheck>( 55 "google-objc-function-naming"); 56 CheckFactories.registerCheck<objc::GlobalVariableDeclarationCheck>( 57 "google-objc-global-variable-declaration"); 58 CheckFactories.registerCheck<runtime::IntegerTypesCheck>( 59 "google-runtime-int"); 60 CheckFactories.registerCheck<runtime::OverloadedUnaryAndCheck>( 61 "google-runtime-operator"); 62 CheckFactories.registerCheck<runtime::NonConstReferences>( 63 "google-runtime-references"); 64 CheckFactories 65 .registerCheck<readability::AvoidUnderscoreInGoogletestNameCheck>( 66 "google-readability-avoid-underscore-in-googletest-name"); 67 CheckFactories.registerCheck<readability::AvoidCStyleCastsCheck>( 68 "google-readability-casting"); 69 CheckFactories.registerCheck<readability::TodoCommentCheck>( 70 "google-readability-todo"); 71 CheckFactories 72 .registerCheck<clang::tidy::readability::BracesAroundStatementsCheck>( 73 "google-readability-braces-around-statements"); 74 CheckFactories.registerCheck<clang::tidy::readability::FunctionSizeCheck>( 75 "google-readability-function-size"); 76 CheckFactories 77 .registerCheck<clang::tidy::readability::NamespaceCommentCheck>( 78 "google-readability-namespace-comments"); 79 } 80 81 ClangTidyOptions getModuleOptions() override { 82 ClangTidyOptions Options; 83 auto &Opts = Options.CheckOptions; 84 Opts["google-readability-braces-around-statements.ShortStatementLines"] = 85 "1"; 86 Opts["google-readability-function-size.StatementThreshold"] = "800"; 87 Opts["google-readability-namespace-comments.ShortNamespaceLines"] = "10"; 88 Opts["google-readability-namespace-comments.SpacesBeforeComments"] = "2"; 89 return Options; 90 } 91 }; 92 93 // Register the GoogleTidyModule using this statically initialized variable. 94 static ClangTidyModuleRegistry::Add<GoogleModule> X("google-module", 95 "Adds Google lint checks."); 96 97 } // namespace google 98 99 // This anchor is used to force the linker to link in the generated object file 100 // and thus register the GoogleModule. 101 volatile int GoogleModuleAnchorSource = 0; 102 103 } // namespace tidy 104 } // namespace clang 105