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

source code of clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp