• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
35 namespace tidy {
36 namespace google {
37 
38 class GoogleModule : public ClangTidyModule {
39  public:
addCheckFactories(ClangTidyCheckFactories & CheckFactories)40   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
41     CheckFactories.registerCheck<build::ExplicitMakePairCheck>(
42         "google-build-explicit-make-pair");
43     CheckFactories.registerCheck<build::UnnamedNamespaceInHeaderCheck>(
44         "google-build-namespaces");
45     CheckFactories.registerCheck<build::UsingNamespaceDirectiveCheck>(
46         "google-build-using-namespace");
47     CheckFactories.registerCheck<DefaultArgumentsCheck>(
48         "google-default-arguments");
49     CheckFactories.registerCheck<ExplicitConstructorCheck>(
50         "google-explicit-constructor");
51     CheckFactories.registerCheck<readability::GlobalNamesInHeadersCheck>(
52         "google-global-names-in-headers");
53     CheckFactories.registerCheck<objc::AvoidNSObjectNewCheck>(
54         "google-objc-avoid-nsobject-new");
55     CheckFactories.registerCheck<objc::AvoidThrowingObjCExceptionCheck>(
56         "google-objc-avoid-throwing-exception");
57     CheckFactories.registerCheck<objc::FunctionNamingCheck>(
58         "google-objc-function-naming");
59     CheckFactories.registerCheck<objc::GlobalVariableDeclarationCheck>(
60         "google-objc-global-variable-declaration");
61     CheckFactories.registerCheck<runtime::IntegerTypesCheck>(
62         "google-runtime-int");
63     CheckFactories.registerCheck<runtime::OverloadedUnaryAndCheck>(
64         "google-runtime-operator");
65     CheckFactories
66         .registerCheck<readability::AvoidUnderscoreInGoogletestNameCheck>(
67             "google-readability-avoid-underscore-in-googletest-name");
68     CheckFactories.registerCheck<readability::AvoidCStyleCastsCheck>(
69         "google-readability-casting");
70     CheckFactories.registerCheck<readability::TodoCommentCheck>(
71         "google-readability-todo");
72     CheckFactories
73         .registerCheck<clang::tidy::readability::BracesAroundStatementsCheck>(
74             "google-readability-braces-around-statements");
75     CheckFactories.registerCheck<clang::tidy::readability::FunctionSizeCheck>(
76         "google-readability-function-size");
77     CheckFactories
78         .registerCheck<clang::tidy::readability::NamespaceCommentCheck>(
79             "google-readability-namespace-comments");
80     CheckFactories.registerCheck<UpgradeGoogletestCaseCheck>(
81         "google-upgrade-googletest-case");
82   }
83 
getModuleOptions()84   ClangTidyOptions getModuleOptions() override {
85     ClangTidyOptions Options;
86     auto &Opts = Options.CheckOptions;
87     Opts["google-readability-braces-around-statements.ShortStatementLines"] =
88         "1";
89     Opts["google-readability-function-size.StatementThreshold"] = "800";
90     Opts["google-readability-namespace-comments.ShortNamespaceLines"] = "10";
91     Opts["google-readability-namespace-comments.SpacesBeforeComments"] = "2";
92     return Options;
93   }
94 };
95 
96 // Register the GoogleTidyModule using this statically initialized variable.
97 static ClangTidyModuleRegistry::Add<GoogleModule> X("google-module",
98                                                     "Adds Google lint checks.");
99 
100 }  // namespace google
101 
102 // This anchor is used to force the linker to link in the generated object file
103 // and thus register the GoogleModule.
104 volatile int GoogleModuleAnchorSource = 0;
105 
106 }  // namespace tidy
107 }  // namespace clang
108