clang-tools 6.0.0

GoogleTidyModule.cpp
Go to the documentation of this file.
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 "AvoidThrowingObjCExceptionCheck.h"
19 #include "DefaultArgumentsCheck.h"
20 #include "ExplicitConstructorCheck.h"
21 #include "ExplicitMakePairCheck.h"
22 #include "GlobalNamesInHeadersCheck.h"
23 #include "GlobalVariableDeclarationCheck.h"
24 #include "IntegerTypesCheck.h"
25 #include "NonConstReferences.h"
26 #include "OverloadedUnaryAndCheck.h"
27 #include "StringReferenceMemberCheck.h"
28 #include "TodoCommentCheck.h"
29 #include "UnnamedNamespaceInHeaderCheck.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:
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::AvoidThrowingObjCExceptionCheck>(
54 "google-objc-avoid-throwing-exception");
55 CheckFactories.registerCheck<objc::GlobalVariableDeclarationCheck>(
56 "google-objc-global-variable-declaration");
57 CheckFactories.registerCheck<runtime::IntegerTypesCheck>(
58 "google-runtime-int");
59 CheckFactories.registerCheck<runtime::OverloadedUnaryAndCheck>(
60 "google-runtime-operator");
61 CheckFactories.registerCheck<runtime::NonConstReferences>(
62 "google-runtime-references");
63 CheckFactories.registerCheck<runtime::StringReferenceMemberCheck>(
64 "google-runtime-member-string-references");
65 CheckFactories.registerCheck<readability::AvoidCStyleCastsCheck>(
66 "google-readability-casting");
67 CheckFactories.registerCheck<readability::TodoCommentCheck>(
68 "google-readability-todo");
69 CheckFactories
70 .registerCheck<clang::tidy::readability::BracesAroundStatementsCheck>(
71 "google-readability-braces-around-statements");
72 CheckFactories.registerCheck<clang::tidy::readability::FunctionSizeCheck>(
73 "google-readability-function-size");
74 CheckFactories
75 .registerCheck<clang::tidy::readability::NamespaceCommentCheck>(
76 "google-readability-namespace-comments");
77 CheckFactories
78 .registerCheck<clang::tidy::readability::RedundantSmartptrGetCheck>(
79 "google-readability-redundant-smartptr-get");
80 }
81
82 ClangTidyOptions getModuleOptions() override {
83 ClangTidyOptions Options;
84 auto &Opts = Options.CheckOptions;
85 Opts["google-readability-braces-around-statements.ShortStatementLines"] =
86 "1";
87 Opts["google-readability-function-size.StatementThreshold"] = "800";
88 Opts["google-readability-namespace-comments.ShortNamespaceLines"] = "10";
89 Opts["google-readability-namespace-comments.SpacesBeforeComments"] = "2";
90 return Options;
91 }
92 };
93
94 // Register the GoogleTidyModule using this statically initialized variable.
95 static ClangTidyModuleRegistry::Add<GoogleModule> X("google-module",
96 "Adds Google lint checks.");
97
98 } // namespace google
99
100 // This anchor is used to force the linker to link in the generated object file
101 // and thus register the GoogleModule.
102 volatile int GoogleModuleAnchorSource = 0;
103
104 } // namespace tidy
105 } // namespace clang
clang::ast_matchers
Definition: ClangTidyDiagnosticConsumer.h:27
clang::tidy::GoogleModuleAnchorSource
volatile int GoogleModuleAnchorSource
Definition: GoogleTidyModule.cpp:102
clang::tidy::google::runtime::OverloadedUnaryAndCheck
Finds overloads of unary operator &.
Definition: OverloadedUnaryAndCheck.h:25
clang::tidy::google::runtime::StringReferenceMemberCheck
Finds members of type const string&.
Definition: StringReferenceMemberCheck.h:41
TodoCommentCheck.h
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:59
clang::tidy::google::readability::GlobalNamesInHeadersCheck
Flag global namespace pollution in header files.
Definition: GlobalNamesInHeadersCheck.h:30
clang::tidy::google::DefaultArgumentsCheck
Checks that default parameters are not given for virtual methods.
Definition: google/DefaultArgumentsCheck.h:22
clang::tidy::google::objc::AvoidThrowingObjCExceptionCheck
The check is to find usage of.
Definition: AvoidThrowingObjCExceptionCheck.h:26
clang::tidy::ClangTidyOptions
Contains options for clang-tidy.
Definition: ClangTidyOptions.h:49
clang::tidy::google::runtime::NonConstReferences
Checks the usage of non-constant references in function parameters.
Definition: NonConstReferences.h:23
clang::tidy::google::build::ExplicitMakePairCheck
Check that make_pair&#39;s template arguments are deduced.
Definition: ExplicitMakePairCheck.h:26
clang::tidy::ClangTidyCheckFactories
A collection of ClangTidyCheckFactory instances.
Definition: ClangTidyModule.h:27
clang::tidy::ClangTidyOptions::CheckOptions
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
Definition: ClangTidyOptions.h:102
NonConstReferences.h
ExplicitMakePairCheck.h
clang::tidy::readability::FunctionSizeCheck
Checks for large functions based on various metrics.
Definition: FunctionSizeCheck.h:36
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:84
clang::tidy::google::build::UnnamedNamespaceInHeaderCheck
Finds anonymous namespaces in headers.
Definition: UnnamedNamespaceInHeaderCheck.h:33
ExplicitConstructorCheck.h
GlobalVariableDeclarationCheck.h
clang::tidy::google::GoogleModule::getModuleOptions
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
Definition: GoogleTidyModule.cpp:82
OverloadedUnaryAndCheck.h
clang::tidy::readability::RedundantSmartptrGetCheck
Find and remove redundant calls to smart pointer&#39;s .get() method.
Definition: RedundantSmartptrGetCheck.h:28
clang::tidy::google::runtime::IntegerTypesCheck
Finds uses of short, long and long long and suggest replacing them with u?intXX(_t)?.
Definition: IntegerTypesCheck.h:29
GlobalNamesInHeadersCheck.h
clang::tidy::google::GoogleModule::addCheckFactories
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module...
Definition: GoogleTidyModule.cpp:40
X
static clang::FrontendPluginRegistry::Add< clang::tidy::ClangTidyPluginAction > X("clang-tidy", "clang-tidy")
clang::tidy::google::readability::TodoCommentCheck
Finds TODO comments without a username or bug number.
Definition: TodoCommentCheck.h:23
UsingNamespaceDirectiveCheck.h
StringReferenceMemberCheck.h
clang::tidy::readability::NamespaceCommentCheck
Checks that long namespaces have a closing comment.
Definition: NamespaceCommentCheck.h:25
clang
Definition: AndroidTidyModule.cpp:28
IntegerTypesCheck.h
clang::tidy::google::build::UsingNamespaceDirectiveCheck
Finds using namespace directives.
Definition: UsingNamespaceDirectiveCheck.h:35
clang::tidy::google::GoogleModule
Definition: GoogleTidyModule.cpp:38
AvoidThrowingObjCExceptionCheck.h
clang::tidy::readability::BracesAroundStatementsCheck
Checks that bodies of if statements and loops (for, range-for, do-while, and while) are inside braces...
Definition: BracesAroundStatementsCheck.h:44
clang::tidy::google::objc::GlobalVariableDeclarationCheck
The check for Objective-C global variables and constants naming convention.
Definition: GlobalVariableDeclarationCheck.h:26
UnnamedNamespaceInHeaderCheck.h
DefaultArgumentsCheck.h
clang::tidy::google::readability::AvoidCStyleCastsCheck
Finds usages of C-style casts.
Definition: AvoidCStyleCastsCheck.h:29
clang::tidy::google::ExplicitConstructorCheck
Checks that all single-argument constructors are explicit.
Definition: ExplicitConstructorCheck.h:22
AvoidCStyleCastsCheck.h