clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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