1 //===--- ModernizeTidyModule.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 "AvoidBindCheck.h"
14 #include "DeprecatedHeadersCheck.h"
15 #include "LoopConvertCheck.h"
16 #include "MakeSharedCheck.h"
17 #include "MakeUniqueCheck.h"
18 #include "PassByValueCheck.h"
19 #include "RawStringLiteralCheck.h"
20 #include "RedundantVoidArgCheck.h"
21 #include "ReplaceAutoPtrCheck.h"
22 #include "ReplaceRandomShuffleCheck.h"
23 #include "ReturnBracedInitListCheck.h"
24 #include "ShrinkToFitCheck.h"
25 #include "UnaryStaticAssertCheck.h"
26 #include "UseAutoCheck.h"
27 #include "UseBoolLiteralsCheck.h"
28 #include "UseDefaultMemberInitCheck.h"
29 #include "UseEmplaceCheck.h"
30 #include "UseEqualsDefaultCheck.h"
31 #include "UseEqualsDeleteCheck.h"
32 #include "UseNoexceptCheck.h"
33 #include "UseNullptrCheck.h"
34 #include "UseOverrideCheck.h"
35 #include "UseTransparentFunctorsCheck.h"
36 #include "UseUncaughtExceptionsCheck.h"
37 #include "UseUsingCheck.h"
38 
39 using namespace clang::ast_matchers;
40 
41 namespace clang {
42 namespace tidy {
43 namespace modernize {
44 
45 class ModernizeModule : public ClangTidyModule {
46 public:
47   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
48     CheckFactories.registerCheck<AvoidBindCheck>("modernize-avoid-bind");
49     CheckFactories.registerCheck<DeprecatedHeadersCheck>(
50         "modernize-deprecated-headers");
51     CheckFactories.registerCheck<LoopConvertCheck>("modernize-loop-convert");
52     CheckFactories.registerCheck<MakeSharedCheck>("modernize-make-shared");
53     CheckFactories.registerCheck<MakeUniqueCheck>("modernize-make-unique");
54     CheckFactories.registerCheck<PassByValueCheck>("modernize-pass-by-value");
55     CheckFactories.registerCheck<RawStringLiteralCheck>(
56         "modernize-raw-string-literal");
57     CheckFactories.registerCheck<RedundantVoidArgCheck>(
58         "modernize-redundant-void-arg");
59     CheckFactories.registerCheck<ReplaceAutoPtrCheck>(
60         "modernize-replace-auto-ptr");
61     CheckFactories.registerCheck<ReplaceRandomShuffleCheck>(
62         "modernize-replace-random-shuffle");
63     CheckFactories.registerCheck<ReturnBracedInitListCheck>(
64         "modernize-return-braced-init-list");
65     CheckFactories.registerCheck<ShrinkToFitCheck>("modernize-shrink-to-fit");
66     CheckFactories.registerCheck<UnaryStaticAssertCheck>(
67         "modernize-unary-static-assert");
68     CheckFactories.registerCheck<UseAutoCheck>("modernize-use-auto");
69     CheckFactories.registerCheck<UseBoolLiteralsCheck>(
70         "modernize-use-bool-literals");
71     CheckFactories.registerCheck<UseDefaultMemberInitCheck>(
72         "modernize-use-default-member-init");
73     CheckFactories.registerCheck<UseEmplaceCheck>("modernize-use-emplace");
74     CheckFactories.registerCheck<UseEqualsDefaultCheck>("modernize-use-equals-default");
75     CheckFactories.registerCheck<UseEqualsDeleteCheck>(
76         "modernize-use-equals-delete");
77     CheckFactories.registerCheck<UseNoexceptCheck>("modernize-use-noexcept");
78     CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr");
79     CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override");
80     CheckFactories.registerCheck<UseTransparentFunctorsCheck>(
81         "modernize-use-transparent-functors");
82     CheckFactories.registerCheck<UseUncaughtExceptionsCheck>(
83         "modernize-use-uncaught-exceptions");
84     CheckFactories.registerCheck<UseUsingCheck>("modernize-use-using");
85   }
86 
87   ClangTidyOptions getModuleOptions() override {
88     ClangTidyOptions Options;
89     auto &Opts = Options.CheckOptions;
90     // For types whose size in bytes is above this threshold, we prefer taking a
91     // const-reference than making a copy.
92     Opts["modernize-loop-convert.MaxCopySize"] = "16";
93 
94     Opts["modernize-loop-convert.MinConfidence"] = "reasonable";
95     Opts["modernize-loop-convert.NamingStyle"] = "CamelCase";
96     Opts["modernize-pass-by-value.IncludeStyle"] = "llvm";    // Also: "google".
97     Opts["modernize-replace-auto-ptr.IncludeStyle"] = "llvm"; // Also: "google".
98 
99     // Comma-separated list of macros that behave like NULL.
100     Opts["modernize-use-nullptr.NullMacros"] = "NULL";
101     return Options;
102   }
103 };
104 
105 // Register the ModernizeTidyModule using this statically initialized variable.
106 static ClangTidyModuleRegistry::Add<ModernizeModule> X("modernize-module",
107                                                        "Add modernize checks.");
108 
109 } // namespace modernize
110 
111 // This anchor is used to force the linker to link in the generated object file
112 // and thus register the ModernizeModule.
113 volatile int ModernizeModuleAnchorSource = 0;
114 
115 } // namespace tidy
116 } // namespace clang
117