clang-tools  15.0.0git
ReadabilityTidyModule.cpp
Go to the documentation of this file.
1 //===--- ReadabilityTidyModule.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"
14 #include "ConstReturnTypeCheck.h"
15 #include "ContainerContainsCheck.h"
19 #include "DeleteNullPointerCheck.h"
20 #include "DuplicateIncludeCheck.h"
21 #include "ElseAfterReturnCheck.h"
23 #include "FunctionSizeCheck.h"
24 #include "IdentifierLengthCheck.h"
25 #include "IdentifierNamingCheck.h"
29 #include "MagicNumbersCheck.h"
33 #include "NamedParameterCheck.h"
34 #include "NonConstParameterCheck.h"
35 #include "QualifiedAutoCheck.h"
49 #include "StringCompareCheck.h"
53 #include "UseAnyOfAllOfCheck.h"
54 
55 namespace clang {
56 namespace tidy {
57 namespace readability {
58 
60 public:
61  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
62  CheckFactories.registerCheck<AvoidConstParamsInDecls>(
63  "readability-avoid-const-params-in-decls");
65  "readability-braces-around-statements");
66  CheckFactories.registerCheck<ConstReturnTypeCheck>(
67  "readability-const-return-type");
68  CheckFactories.registerCheck<ContainerContainsCheck>(
69  "readability-container-contains");
71  "readability-container-data-pointer");
72  CheckFactories.registerCheck<ContainerSizeEmptyCheck>(
73  "readability-container-size-empty");
75  "readability-convert-member-functions-to-static");
76  CheckFactories.registerCheck<DeleteNullPointerCheck>(
77  "readability-delete-null-pointer");
78  CheckFactories.registerCheck<DuplicateIncludeCheck>(
79  "readability-duplicate-include");
80  CheckFactories.registerCheck<ElseAfterReturnCheck>(
81  "readability-else-after-return");
83  "readability-function-cognitive-complexity");
84  CheckFactories.registerCheck<FunctionSizeCheck>(
85  "readability-function-size");
86  CheckFactories.registerCheck<IdentifierLengthCheck>(
87  "readability-identifier-length");
88  CheckFactories.registerCheck<IdentifierNamingCheck>(
89  "readability-identifier-naming");
91  "readability-implicit-bool-conversion");
93  "readability-inconsistent-declaration-parameter-name");
94  CheckFactories.registerCheck<IsolateDeclarationCheck>(
95  "readability-isolate-declaration");
96  CheckFactories.registerCheck<MagicNumbersCheck>(
97  "readability-magic-numbers");
99  "readability-make-member-function-const");
101  "readability-misleading-indentation");
102  CheckFactories.registerCheck<MisplacedArrayIndexCheck>(
103  "readability-misplaced-array-index");
104  CheckFactories.registerCheck<QualifiedAutoCheck>(
105  "readability-qualified-auto");
107  "readability-redundant-access-specifiers");
109  "readability-redundant-function-ptr-dereference");
110  CheckFactories.registerCheck<RedundantMemberInitCheck>(
111  "readability-redundant-member-init");
113  "readability-redundant-preprocessor");
115  "readability-simplify-subscript-expr");
117  "readability-static-accessed-through-instance");
119  "readability-static-definition-in-anonymous-namespace");
120  CheckFactories.registerCheck<StringCompareCheck>(
121  "readability-string-compare");
123  "readability-named-parameter");
124  CheckFactories.registerCheck<NonConstParameterCheck>(
125  "readability-non-const-parameter");
127  "readability-redundant-control-flow");
129  "readability-redundant-declaration");
131  "readability-redundant-smartptr-get");
132  CheckFactories.registerCheck<RedundantStringCStrCheck>(
133  "readability-redundant-string-cstr");
134  CheckFactories.registerCheck<RedundantStringInitCheck>(
135  "readability-redundant-string-init");
136  CheckFactories.registerCheck<SimplifyBooleanExprCheck>(
137  "readability-simplify-boolean-expr");
139  "readability-suspicious-call-argument");
141  "readability-uniqueptr-delete-release");
143  "readability-uppercase-literal-suffix");
144  CheckFactories.registerCheck<UseAnyOfAllOfCheck>(
145  "readability-use-anyofallof");
146  }
147 };
148 
149 // Register the ReadabilityModule using this statically initialized variable.
150 static ClangTidyModuleRegistry::Add<ReadabilityModule>
151  X("readability-module", "Adds readability-related checks.");
152 
153 } // namespace readability
154 
155 // This anchor is used to force the linker to link in the generated object file
156 // and thus register the ReadabilityModule.
158 
159 } // namespace tidy
160 } // namespace clang
ImplicitBoolConversionCheck.h
clang::tidy::readability::SuspiciousCallArgumentCheck
Finds function calls where the arguments passed are provided out of order, based on the difference be...
Definition: SuspiciousCallArgumentCheck.h:25
clang::tidy::readability::RedundantStringCStrCheck
Finds unnecessary calls to std::string::c_str().
Definition: RedundantStringCStrCheck.h:19
clang::tidy::readability::MisleadingIndentationCheck
Checks the code for dangling else, and possible misleading indentations due to missing braces.
Definition: MisleadingIndentationCheck.h:24
clang::tidy::ReadabilityModuleAnchorSource
volatile int ReadabilityModuleAnchorSource
Definition: ReadabilityTidyModule.cpp:157
AvoidConstParamsInDecls.h
IsolateDeclarationCheck.h
InconsistentDeclarationParameterNameCheck.h
clang::tidy::readability::RedundantDeclarationCheck
Find redundant variable declarations.
Definition: RedundantDeclarationCheck.h:22
clang::tidy::readability::BracesAroundStatementsCheck
Checks that bodies of if statements and loops (for, range-for, do-while, and while) are inside braces...
Definition: BracesAroundStatementsCheck.h:43
ContainerContainsCheck.h
RedundantStringInitCheck.h
FunctionCognitiveComplexityCheck.h
clang::tidy::readability::RedundantSmartptrGetCheck
Find and remove redundant calls to smart pointer's .get() method.
Definition: RedundantSmartptrGetCheck.h:27
clang::tidy::readability::RedundantFunctionPtrDereferenceCheck
Eliminate redundant dereferences of a function pointer.
Definition: RedundantFunctionPtrDereferenceCheck.h:22
QualifiedAutoCheck.h
IdentifierNamingCheck.h
clang::tidy::readability::MakeMemberFunctionConstCheck
Finds non-static member functions that can be made 'const'.
Definition: MakeMemberFunctionConstCheck.h:22
clang::tidy::readability::RedundantMemberInitCheck
Finds member initializations that are unnecessary because the same default constructor would be calle...
Definition: RedundantMemberInitCheck.h:23
RedundantFunctionPtrDereferenceCheck.h
clang::tidy::readability::RedundantControlFlowCheck
Eliminates redundant return statements at the end of a function that returns void.
Definition: RedundantControlFlowCheck.h:25
clang::tidy::readability::RedundantStringInitCheck
Finds unnecessary string initializations.
Definition: RedundantStringInitCheck.h:21
RedundantAccessSpecifiersCheck.h
clang::tidy::ClangTidyCheckFactories
A collection of ClangTidyCheckFactory instances.
Definition: ClangTidyModule.h:28
clang::tidy::readability::ReadabilityModule::addCheckFactories
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module.
Definition: ReadabilityTidyModule.cpp:61
clang::tidy::readability::UppercaseLiteralSuffixCheck
Detects when the integral literal or floating point literal has non-uppercase suffix,...
Definition: UppercaseLiteralSuffixCheck.h:25
BracesAroundStatementsCheck.h
clang::tidy::readability::InconsistentDeclarationParameterNameCheck
Checks for declarations of functions which differ in parameter names.
Definition: InconsistentDeclarationParameterNameCheck.h:25
ConvertMemberFunctionsToStatic.h
DeleteNullPointerCheck.h
DuplicateIncludeCheck.h
StringCompareCheck.h
IdentifierLengthCheck.h
clang::tidy::readability::ContainerSizeEmptyCheck
Checks whether a call to the size() method can be replaced with a call to empty().
Definition: ContainerSizeEmptyCheck.h:28
UniqueptrDeleteReleaseCheck.h
ConstReturnTypeCheck.h
clang::tidy::readability::NonConstParameterCheck
Warn when a pointer function parameter can be const.
Definition: NonConstParameterCheck.h:22
clang::tidy::readability::IdentifierLengthCheck
Warns about identifiers names whose length is too short.
Definition: IdentifierLengthCheck.h:24
clang::tidy::readability::ContainerContainsCheck
Finds usages of container.count() and find() == end() which should be replaced by a call to the conta...
Definition: ContainerContainsCheck.h:23
NamedParameterCheck.h
RedundantSmartptrGetCheck.h
SuspiciousCallArgumentCheck.h
RedundantStringCStrCheck.h
clang::tidy::readability::SimplifyBooleanExprCheck
Looks for boolean expressions involving boolean constants and simplifies them to use the appropriate ...
Definition: SimplifyBooleanExprCheck.h:23
UseAnyOfAllOfCheck.h
ContainerDataPointerCheck.h
StaticAccessedThroughInstanceCheck.h
clang::tidy::readability::FunctionSizeCheck
Checks for large functions based on various metrics.
Definition: FunctionSizeCheck.h:37
clang::tidy::readability::StringCompareCheck
This check flags all calls compare when used to check for string equality or inequality.
Definition: StringCompareCheck.h:23
MisplacedArrayIndexCheck.h
clang::tidy::readability::MagicNumbersCheck
Detects magic numbers, integer and floating point literals embedded in code.
Definition: MagicNumbersCheck.h:25
ContainerSizeEmptyCheck.h
SimplifyBooleanExprCheck.h
clang::tidy::readability::ConvertMemberFunctionsToStatic
This check finds C++ class methods than can be made static because they don't use the 'this' pointer.
Definition: ConvertMemberFunctionsToStatic.h:24
clang::tidy::readability::StaticAccessedThroughInstanceCheck
Checks for member expressions that access static members through instances and replaces them with use...
Definition: StaticAccessedThroughInstanceCheck.h:23
clang::tidy::readability::ReadabilityModule
Definition: ReadabilityTidyModule.cpp:59
clang::tidy::readability::UseAnyOfAllOfCheck
Finds ranged-based for loops that can be replaced by a call to std::any_of or std::all_of.
Definition: UseAnyOfAllOfCheck.h:24
RedundantPreprocessorCheck.h
clang::tidy::readability::ElseAfterReturnCheck
Flags the usages of else after return.
Definition: ElseAfterReturnCheck.h:22
clang::tidy::readability::MisplacedArrayIndexCheck
Warn about unusual array index syntax (index[array] instead of array[index]).
Definition: MisplacedArrayIndexCheck.h:23
SimplifySubscriptExprCheck.h
RedundantDeclarationCheck.h
clang::tidy::readability::SimplifySubscriptExprCheck
Simplifies subscript expressions.
Definition: SimplifySubscriptExprCheck.h:22
StaticDefinitionInAnonymousNamespaceCheck.h
clang::tidy::readability::IsolateDeclarationCheck
This check diagnoses all DeclStmt's declaring more than one variable and tries to refactor the code t...
Definition: IsolateDeclarationCheck.h:23
clang::tidy::readability::IdentifierNamingCheck
Checks for identifiers naming style mismatch.
Definition: IdentifierNamingCheck.h:33
clang::tidy::readability::DuplicateIncludeCheck
Find and remove duplicate #include directives.
Definition: DuplicateIncludeCheck.h:22
clang::tidy::readability::AvoidConstParamsInDecls
Definition: AvoidConstParamsInDecls.h:20
clang::tidy::readability::NamedParameterCheck
Find functions with unnamed arguments.
Definition: NamedParameterCheck.h:29
clang::tidy::readability::X
static ClangTidyModuleRegistry::Add< ReadabilityModule > X("readability-module", "Adds readability-related checks.")
MisleadingIndentationCheck.h
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
RedundantControlFlowCheck.h
MagicNumbersCheck.h
ElseAfterReturnCheck.h
NonConstParameterCheck.h
clang::tidy::readability::FunctionCognitiveComplexityCheck
Checks function Cognitive Complexity metric.
Definition: FunctionCognitiveComplexityCheck.h:34
clang::tidy::readability::QualifiedAutoCheck
Finds variables declared as auto that could be declared as: 'auto*' or 'const auto *' and reference v...
Definition: QualifiedAutoCheck.h:24
clang::tidy::readability::UniqueptrDeleteReleaseCheck
Flags statements of the form delete <unique_ptr expr>.release(); and replaces them with: <unique_ptr ...
Definition: UniqueptrDeleteReleaseCheck.h:23
clang::tidy::readability::RedundantPreprocessorCheck
This check flags redundant preprocessor directives: nested directives with the same condition.
Definition: RedundantPreprocessorCheck.h:23
clang::tidy::readability::RedundantAccessSpecifiersCheck
Detects redundant access specifiers inside classes, structs, and unions.
Definition: RedundantAccessSpecifiersCheck.h:22
UppercaseLiteralSuffixCheck.h
clang::tidy::readability::ContainerDataPointerCheck
Checks whether a call to operator[] and & can be replaced with a call to data().
Definition: ContainerDataPointerCheck.h:25
MakeMemberFunctionConstCheck.h
clang::tidy::readability::DeleteNullPointerCheck
Check whether the 'if' statement is unnecessary before calling 'delete' on a pointer.
Definition: DeleteNullPointerCheck.h:23
clang::tidy::readability::ImplicitBoolConversionCheck
Checks for use of implicit bool conversions in expressions.
Definition: ImplicitBoolConversionCheck.h:22
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:85
clang::tidy::readability::ConstReturnTypeCheck
For any function whose return type is const-qualified, suggests removal of the const qualifier from t...
Definition: ConstReturnTypeCheck.h:23
RedundantMemberInitCheck.h
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(llvm::StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:59
FunctionSizeCheck.h
clang::tidy::readability::StaticDefinitionInAnonymousNamespaceCheck
Finds static function and variable definitions in anonymous namespace.
Definition: StaticDefinitionInAnonymousNamespaceCheck.h:22