| 1 |
//===-- CppCoreGuidelinesTidyModule.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 "../misc/NonPrivateMemberVariablesInClassesCheck.h" |
| 13 |
#include "../misc/UnconventionalAssignOperatorCheck.h" |
| 14 |
#include "../modernize/AvoidCArraysCheck.h" |
| 15 |
#include "../modernize/UseOverrideCheck.h" |
| 16 |
#include "../readability/MagicNumbersCheck.h" |
| 17 |
#include "AvoidConstOrRefDataMembersCheck.h" |
| 18 |
#include "AvoidDoWhileCheck.h" |
| 19 |
#include "AvoidGotoCheck.h" |
| 20 |
#include "AvoidNonConstGlobalVariablesCheck.h" |
| 21 |
#include "AvoidReferenceCoroutineParametersCheck.h" |
| 22 |
#include "InitVariablesCheck.h" |
| 23 |
#include "InterfacesGlobalInitCheck.h" |
| 24 |
#include "MacroUsageCheck.h" |
| 25 |
#include "NarrowingConversionsCheck.h" |
| 26 |
#include "NoMallocCheck.h" |
| 27 |
#include "OwningMemoryCheck.h" |
| 28 |
#include "PreferMemberInitializerCheck.h" |
| 29 |
#include "ProBoundsArrayToPointerDecayCheck.h" |
| 30 |
#include "ProBoundsConstantArrayIndexCheck.h" |
| 31 |
#include "ProBoundsPointerArithmeticCheck.h" |
| 32 |
#include "ProTypeConstCastCheck.h" |
| 33 |
#include "ProTypeCstyleCastCheck.h" |
| 34 |
#include "ProTypeMemberInitCheck.h" |
| 35 |
#include "ProTypeReinterpretCastCheck.h" |
| 36 |
#include "ProTypeStaticCastDowncastCheck.h" |
| 37 |
#include "ProTypeUnionAccessCheck.h" |
| 38 |
#include "ProTypeVarargCheck.h" |
| 39 |
#include "SlicingCheck.h" |
| 40 |
#include "SpecialMemberFunctionsCheck.h" |
| 41 |
#include "VirtualClassDestructorCheck.h" |
| 42 |
|
| 43 |
namespace clang::tidy { |
| 44 |
namespace cppcoreguidelines { |
| 45 |
|
| 46 |
/// A module containing checks of the C++ Core Guidelines |
| 47 |
class CppCoreGuidelinesModule : public ClangTidyModule { |
| 48 |
public: |
| 49 |
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { |
| 50 |
CheckFactories.registerCheck<modernize::AvoidCArraysCheck>( |
| 51 |
"cppcoreguidelines-avoid-c-arrays"); |
| 52 |
CheckFactories.registerCheck<AvoidConstOrRefDataMembersCheck>( |
| 53 |
"cppcoreguidelines-avoid-const-or-ref-data-members"); |
| 54 |
CheckFactories.registerCheck<AvoidDoWhileCheck>( |
| 55 |
"cppcoreguidelines-avoid-do-while"); |
| 56 |
CheckFactories.registerCheck<AvoidGotoCheck>( |
| 57 |
"cppcoreguidelines-avoid-goto"); |
| 58 |
CheckFactories.registerCheck<readability::MagicNumbersCheck>( |
| 59 |
"cppcoreguidelines-avoid-magic-numbers"); |
| 60 |
CheckFactories.registerCheck<AvoidNonConstGlobalVariablesCheck>( |
| 61 |
"cppcoreguidelines-avoid-non-const-global-variables"); |
| 62 |
CheckFactories.registerCheck<AvoidReferenceCoroutineParametersCheck>( |
| 63 |
"cppcoreguidelines-avoid-reference-coroutine-parameters"); |
| 64 |
CheckFactories.registerCheck<modernize::UseOverrideCheck>( |
| 65 |
"cppcoreguidelines-explicit-virtual-functions"); |
| 66 |
CheckFactories.registerCheck<InitVariablesCheck>( |
| 67 |
"cppcoreguidelines-init-variables"); |
| 68 |
CheckFactories.registerCheck<InterfacesGlobalInitCheck>( |
| 69 |
"cppcoreguidelines-interfaces-global-init"); |
| 70 |
CheckFactories.registerCheck<MacroUsageCheck>( |
| 71 |
"cppcoreguidelines-macro-usage"); |
| 72 |
CheckFactories.registerCheck<NarrowingConversionsCheck>( |
| 73 |
"cppcoreguidelines-narrowing-conversions"); |
| 74 |
CheckFactories.registerCheck<NoMallocCheck>("cppcoreguidelines-no-malloc"); |
| 75 |
CheckFactories.registerCheck<misc::NonPrivateMemberVariablesInClassesCheck>( |
| 76 |
"cppcoreguidelines-non-private-member-variables-in-classes"); |
| 77 |
CheckFactories.registerCheck<OwningMemoryCheck>( |
| 78 |
"cppcoreguidelines-owning-memory"); |
| 79 |
CheckFactories.registerCheck<PreferMemberInitializerCheck>( |
| 80 |
"cppcoreguidelines-prefer-member-initializer"); |
| 81 |
CheckFactories.registerCheck<ProBoundsArrayToPointerDecayCheck>( |
| 82 |
"cppcoreguidelines-pro-bounds-array-to-pointer-decay"); |
| 83 |
CheckFactories.registerCheck<ProBoundsConstantArrayIndexCheck>( |
| 84 |
"cppcoreguidelines-pro-bounds-constant-array-index"); |
| 85 |
CheckFactories.registerCheck<ProBoundsPointerArithmeticCheck>( |
| 86 |
"cppcoreguidelines-pro-bounds-pointer-arithmetic"); |
| 87 |
CheckFactories.registerCheck<ProTypeConstCastCheck>( |
| 88 |
"cppcoreguidelines-pro-type-const-cast"); |
| 89 |
CheckFactories.registerCheck<ProTypeCstyleCastCheck>( |
| 90 |
"cppcoreguidelines-pro-type-cstyle-cast"); |
| 91 |
CheckFactories.registerCheck<ProTypeMemberInitCheck>( |
| 92 |
"cppcoreguidelines-pro-type-member-init"); |
| 93 |
CheckFactories.registerCheck<ProTypeReinterpretCastCheck>( |
| 94 |
"cppcoreguidelines-pro-type-reinterpret-cast"); |
| 95 |
CheckFactories.registerCheck<ProTypeStaticCastDowncastCheck>( |
| 96 |
"cppcoreguidelines-pro-type-static-cast-downcast"); |
| 97 |
CheckFactories.registerCheck<ProTypeUnionAccessCheck>( |
| 98 |
"cppcoreguidelines-pro-type-union-access"); |
| 99 |
CheckFactories.registerCheck<ProTypeVarargCheck>( |
| 100 |
"cppcoreguidelines-pro-type-vararg"); |
| 101 |
CheckFactories.registerCheck<SpecialMemberFunctionsCheck>( |
| 102 |
"cppcoreguidelines-special-member-functions"); |
| 103 |
CheckFactories.registerCheck<SlicingCheck>("cppcoreguidelines-slicing"); |
| 104 |
CheckFactories.registerCheck<misc::UnconventionalAssignOperatorCheck>( |
| 105 |
"cppcoreguidelines-c-copy-assignment-signature"); |
| 106 |
CheckFactories.registerCheck<VirtualClassDestructorCheck>( |
| 107 |
"cppcoreguidelines-virtual-class-destructor"); |
| 108 |
} |
| 109 |
|
| 110 |
ClangTidyOptions getModuleOptions() override { |
| 111 |
ClangTidyOptions Options; |
| 112 |
ClangTidyOptions::OptionMap &Opts = Options.CheckOptions; |
| 113 |
|
| 114 |
Opts["cppcoreguidelines-non-private-member-variables-in-classes." |
| 115 |
"IgnoreClassesWithAllMemberVariablesBeingPublic"] = "true"; |
| 116 |
|
| 117 |
return Options; |
| 118 |
} |
| 119 |
}; |
| 120 |
|
| 121 |
// Register the LLVMTidyModule using this statically initialized variable. |
| 122 |
static ClangTidyModuleRegistry::Add<CppCoreGuidelinesModule> |
| 123 |
X("cppcoreguidelines-module", "Adds checks for the C++ Core Guidelines."); |
| 124 |
|
| 125 |
} // namespace cppcoreguidelines |
| 126 |
|
| 127 |
// This anchor is used to force the linker to link in the generated object file |
| 128 |
// and thus register the CppCoreGuidelinesModule. |
| 129 |
volatile int CppCoreGuidelinesModuleAnchorSource = 0; |
| 130 |
|
| 131 |
} // namespace clang::tidy |