clang-tools  11.0.0
GoogleTidyModule.cpp
Go to the documentation of this file.
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"
19 #include "DefaultArgumentsCheck.h"
21 #include "ExplicitMakePairCheck.h"
22 #include "FunctionNamingCheck.h"
25 #include "IntegerTypesCheck.h"
26 #include "NonConstReferences.h"
28 #include "TodoCommentCheck.h"
32 
33 using namespace clang::ast_matchers;
34 
35 namespace clang {
36 namespace tidy {
37 namespace google {
38 
39 class GoogleModule : public ClangTidyModule {
40  public:
41  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
43  "google-build-explicit-make-pair");
45  "google-build-namespaces");
47  "google-build-using-namespace");
48  CheckFactories.registerCheck<DefaultArgumentsCheck>(
49  "google-default-arguments");
51  "google-explicit-constructor");
53  "google-global-names-in-headers");
55  "google-objc-avoid-nsobject-new");
57  "google-objc-avoid-throwing-exception");
59  "google-objc-function-naming");
61  "google-objc-global-variable-declaration");
63  "google-runtime-int");
65  "google-runtime-operator");
67  "google-runtime-references");
68  CheckFactories
70  "google-readability-avoid-underscore-in-googletest-name");
72  "google-readability-casting");
74  "google-readability-todo");
75  CheckFactories
77  "google-readability-braces-around-statements");
79  "google-readability-function-size");
80  CheckFactories
82  "google-readability-namespace-comments");
84  "google-upgrade-googletest-case");
85  }
86 
88  ClangTidyOptions Options;
89  auto &Opts = Options.CheckOptions;
90  Opts["google-readability-braces-around-statements.ShortStatementLines"] =
91  "1";
92  Opts["google-readability-function-size.StatementThreshold"] = "800";
93  Opts["google-readability-namespace-comments.ShortNamespaceLines"] = "10";
94  Opts["google-readability-namespace-comments.SpacesBeforeComments"] = "2";
95  return Options;
96  }
97 };
98 
99 // Register the GoogleTidyModule using this statically initialized variable.
100 static ClangTidyModuleRegistry::Add<GoogleModule> X("google-module",
101  "Adds Google lint checks.");
102 
103 } // namespace google
104 
105 // This anchor is used to force the linker to link in the generated object file
106 // and thus register the GoogleModule.
107 volatile int GoogleModuleAnchorSource = 0;
108 
109 } // namespace tidy
110 } // namespace clang
clang::tidy::google::readability::TodoCommentCheck
Finds TODO comments without a username or bug number.
Definition: TodoCommentCheck.h:22
clang::tidy::readability::NamespaceCommentCheck
Checks that long namespaces have a closing comment.
Definition: NamespaceCommentCheck.h:24
ExplicitConstructorCheck.h
clang::tidy::google::readability::GlobalNamesInHeadersCheck
Flag global namespace pollution in header files.
Definition: GlobalNamesInHeadersCheck.h:30
UsingNamespaceDirectiveCheck.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:43
clang::tidy::google::ExplicitConstructorCheck
Checks that all single-argument constructors are explicit.
Definition: ExplicitConstructorCheck.h:21
AvoidNSObjectNewCheck.h
clang::tidy::ClangTidyOptions::CheckOptions
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
Definition: ClangTidyOptions.h:114
clang::tidy::google::objc::FunctionNamingCheck
Finds function names that do not conform to the recommendations of the Google Objective-C Style Guide...
Definition: FunctionNamingCheck.h:29
clang::tidy::ClangTidyOptions
Contains options for clang-tidy.
Definition: ClangTidyOptions.h:50
clang::tidy::google::runtime::NonConstReferences
Checks the usage of non-constant references in function parameters.
Definition: NonConstReferences.h:22
FunctionNamingCheck.h
clang::ast_matchers
Definition: AbseilMatcher.h:14
clang::tidy::ClangTidyCheckFactories
A collection of ClangTidyCheckFactory instances.
Definition: ClangTidyModule.h:30
ExplicitMakePairCheck.h
TodoCommentCheck.h
clang::tidy::google::objc::GlobalVariableDeclarationCheck
The check for Objective-C global variables and constants naming convention.
Definition: GlobalVariableDeclarationCheck.h:25
clang::tidy::google::build::UsingNamespaceDirectiveCheck
Finds using namespace directives.
Definition: UsingNamespaceDirectiveCheck.h:34
clang::tidy::google::UpgradeGoogletestCaseCheck
Finds uses of deprecated Googletest APIs with names containing "case" and replaces them with equivale...
Definition: UpgradeGoogletestCaseCheck.h:23
AvoidCStyleCastsCheck.h
clang::tidy::google::DefaultArgumentsCheck
Checks that default parameters are not given for virtual methods.
Definition: DefaultArgumentsCheck.h:21
clang::tidy::google::build::ExplicitMakePairCheck
Check that make_pair's template arguments are deduced.
Definition: ExplicitMakePairCheck.h:25
clang::tidy::google::build::UnnamedNamespaceInHeaderCheck
Finds anonymous namespaces in headers.
Definition: UnnamedNamespaceInHeaderCheck.h:33
clang::tidy::google::readability::AvoidUnderscoreInGoogletestNameCheck
Definition: AvoidUnderscoreInGoogletestNameCheck.h:21
clang::tidy::google::X
static ClangTidyModuleRegistry::Add< GoogleModule > X("google-module", "Adds Google lint checks.")
GlobalVariableDeclarationCheck.h
clang::tidy::google::GoogleModule
Definition: GoogleTidyModule.cpp:39
IntegerTypesCheck.h
OverloadedUnaryAndCheck.h
clang::tidy::readability::FunctionSizeCheck
Checks for large functions based on various metrics.
Definition: FunctionSizeCheck.h:37
GlobalNamesInHeadersCheck.h
clang::tidy::google::runtime::IntegerTypesCheck
Finds uses of short, long and long long and suggest replacing them with u?intXX(_t)?...
Definition: IntegerTypesCheck.h:28
clang::tidy::google::readability::AvoidCStyleCastsCheck
Finds usages of C-style casts.
Definition: AvoidCStyleCastsCheck.h:28
clang::tidy::google::objc::AvoidThrowingObjCExceptionCheck
The check is to find usage of.
Definition: AvoidThrowingObjCExceptionCheck.h:25
clang::tidy::google::objc::AvoidNSObjectNewCheck
This check finds Objective-C code that uses +new to create object instances, or overrides +new in cla...
Definition: AvoidNSObjectNewCheck.h:25
UpgradeGoogletestCaseCheck.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:41
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
AvoidUnderscoreInGoogletestNameCheck.h
NonConstReferences.h
DefaultArgumentsCheck.h
clang::tidy::google::runtime::OverloadedUnaryAndCheck
Finds overloads of unary operator &.
Definition: OverloadedUnaryAndCheck.h:24
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:83
UnnamedNamespaceInHeaderCheck.h
clang::tidy::google::GoogleModule::getModuleOptions
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
Definition: GoogleTidyModule.cpp:87
AvoidThrowingObjCExceptionCheck.h
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(llvm::StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:61
clang::tidy::GoogleModuleAnchorSource
volatile int GoogleModuleAnchorSource
Definition: GoogleTidyModule.cpp:107