clang-tools  3.8.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"
19 #include "ExplicitMakePairCheck.h"
21 #include "IntegerTypesCheck.h"
22 #include "MemsetZeroLengthCheck.h"
25 #include "TodoCommentCheck.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 {
39  "google-build-explicit-make-pair");
41  "google-build-namespaces");
43  "google-build-using-namespace");
45  "google-explicit-constructor");
47  "google-runtime-int");
49  "google-runtime-operator");
51  "google-runtime-member-string-references");
53  "google-runtime-memset");
55  "google-readability-casting");
57  "google-readability-todo");
58  CheckFactories
60  "google-readability-braces-around-statements");
62  "google-global-names-in-headers");
64  "google-readability-function-size");
65  CheckFactories
67  "google-readability-namespace-comments");
68  CheckFactories
70  "google-readability-redundant-smartptr-get");
71  }
72 
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
volatile int GoogleModuleAnchorSource
void registerCheck(StringRef CheckName)
Registers the CheckType with the name Name.
Contains options for clang-tidy.
static ClangTidyModuleRegistry::Add< GoogleModule > X("google-module","Adds Google lint checks.")
Check that make_pair's template arguments are deduced.
A collection of ClangTidyCheckFactory instances.
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
Checks for large functions based on various metrics.
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
Find and remove redundant calls to smart pointer's .get() method.
Finds uses of short, long and long long and suggest replacing them with u?intXX(_t)?.
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module...
Finds TODO comments without a username or bug number.
Checks that long namespaces have a closing comment.
Finds calls to memset with a literal zero in the length argument.
Checks that bodies of if statements and loops (for, range-for, do-while, and while) are inside braces...
Checks that all single-argument constructors are explicit.