xref: /llvm-project/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp (revision 7d2ea6c422d3f5712b7253407005e1a465a76946)
1 //===--- LLVMTidyModule.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/ElseAfterReturnCheck.h"
13 #include "../readability/NamespaceCommentCheck.h"
14 #include "../readability/QualifiedAutoCheck.h"
15 #include "HeaderGuardCheck.h"
16 #include "IncludeOrderCheck.h"
17 #include "PreferIsaOrDynCastInConditionalsCheck.h"
18 #include "PreferRegisterOverUnsignedCheck.h"
19 #include "TwineLocalCheck.h"
20 
21 namespace clang::tidy {
22 namespace llvm_check {
23 
24 class LLVMModule : public ClangTidyModule {
25 public:
addCheckFactories(ClangTidyCheckFactories & CheckFactories)26   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
27     CheckFactories.registerCheck<readability::ElseAfterReturnCheck>(
28         "llvm-else-after-return");
29     CheckFactories.registerCheck<LLVMHeaderGuardCheck>("llvm-header-guard");
30     CheckFactories.registerCheck<IncludeOrderCheck>("llvm-include-order");
31     CheckFactories.registerCheck<readability::NamespaceCommentCheck>(
32         "llvm-namespace-comment");
33     CheckFactories.registerCheck<PreferIsaOrDynCastInConditionalsCheck>(
34         "llvm-prefer-isa-or-dyn-cast-in-conditionals");
35     CheckFactories.registerCheck<PreferRegisterOverUnsignedCheck>(
36         "llvm-prefer-register-over-unsigned");
37     CheckFactories.registerCheck<readability::QualifiedAutoCheck>(
38         "llvm-qualified-auto");
39     CheckFactories.registerCheck<TwineLocalCheck>("llvm-twine-local");
40   }
41 
getModuleOptions()42   ClangTidyOptions getModuleOptions() override {
43     ClangTidyOptions Options;
44     Options.CheckOptions["llvm-qualified-auto.AddConstToQualified"] = "false";
45     Options.CheckOptions["llvm-else-after-return.WarnOnUnfixable"] = "false";
46     Options.CheckOptions["llvm-else-after-return.WarnOnConditionVariables"] =
47         "false";
48     return Options;
49   }
50 };
51 
52 // Register the LLVMTidyModule using this statically initialized variable.
53 static ClangTidyModuleRegistry::Add<LLVMModule> X("llvm-module",
54                                                   "Adds LLVM lint checks.");
55 
56 } // namespace llvm_check
57 
58 // This anchor is used to force the linker to link in the generated object file
59 // and thus register the LLVMModule.
60 volatile int LLVMModuleAnchorSource = 0;
61 
62 } // namespace clang::tidy
63