xref: /llvm-project/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp (revision 7d2ea6c422d3f5712b7253407005e1a465a76946)
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 "AvoidNSObjectNewCheck.h"
17 #include "AvoidThrowingObjCExceptionCheck.h"
18 #include "AvoidUnderscoreInGoogletestNameCheck.h"
19 #include "DefaultArgumentsCheck.h"
20 #include "ExplicitConstructorCheck.h"
21 #include "ExplicitMakePairCheck.h"
22 #include "FunctionNamingCheck.h"
23 #include "GlobalNamesInHeadersCheck.h"
24 #include "GlobalVariableDeclarationCheck.h"
25 #include "IntegerTypesCheck.h"
26 #include "OverloadedUnaryAndCheck.h"
27 #include "TodoCommentCheck.h"
28 #include "UnnamedNamespaceInHeaderCheck.h"
29 #include "UpgradeGoogletestCaseCheck.h"
30 #include "UsingNamespaceDirectiveCheck.h"
31 
32 using namespace clang::ast_matchers;
33 
34 namespace clang::tidy {
35 namespace google {
36 
37 class GoogleModule : public ClangTidyModule {
38  public:
addCheckFactories(ClangTidyCheckFactories & CheckFactories)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::AvoidNSObjectNewCheck>(
53         "google-objc-avoid-nsobject-new");
54     CheckFactories.registerCheck<objc::AvoidThrowingObjCExceptionCheck>(
55         "google-objc-avoid-throwing-exception");
56     CheckFactories.registerCheck<objc::FunctionNamingCheck>(
57         "google-objc-function-naming");
58     CheckFactories.registerCheck<objc::GlobalVariableDeclarationCheck>(
59         "google-objc-global-variable-declaration");
60     CheckFactories.registerCheck<runtime::IntegerTypesCheck>(
61         "google-runtime-int");
62     CheckFactories.registerCheck<runtime::OverloadedUnaryAndCheck>(
63         "google-runtime-operator");
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     CheckFactories.registerCheck<UpgradeGoogletestCaseCheck>(
80         "google-upgrade-googletest-case");
81   }
82 
getModuleOptions()83   ClangTidyOptions getModuleOptions() override {
84     ClangTidyOptions Options;
85     auto &Opts = Options.CheckOptions;
86     Opts["google-readability-braces-around-statements.ShortStatementLines"] =
87         "1";
88     Opts["google-readability-function-size.StatementThreshold"] = "800";
89     Opts["google-readability-namespace-comments.ShortNamespaceLines"] = "10";
90     Opts["google-readability-namespace-comments.SpacesBeforeComments"] = "2";
91     return Options;
92   }
93 };
94 
95 // Register the GoogleTidyModule using this statically initialized variable.
96 static ClangTidyModuleRegistry::Add<GoogleModule> X("google-module",
97                                                     "Adds Google lint checks.");
98 
99 }  // namespace google
100 
101 // This anchor is used to force the linker to link in the generated object file
102 // and thus register the GoogleModule.
103 volatile int GoogleModuleAnchorSource = 0;
104 
105 } // namespace clang::tidy
106