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