clang-tools 19.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"
27#include "FunctionSizeCheck.h"
33#include "MagicNumbersCheck.h"
37#include "NamedParameterCheck.h"
40#include "QualifiedAutoCheck.h"
57#include "StringCompareCheck.h"
61#include "UseAnyOfAllOfCheck.h"
62#include "UseStdMinMaxCheck.h"
63
64namespace clang::tidy {
65namespace readability {
66
68public:
69 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
71 "readability-avoid-const-params-in-decls");
73 "readability-avoid-nested-conditional-operator");
75 "readability-avoid-return-with-void-value");
77 "readability-avoid-unconditional-preprocessor-if");
79 "readability-braces-around-statements");
80 CheckFactories.registerCheck<ConstReturnTypeCheck>(
81 "readability-const-return-type");
83 "readability-container-contains");
85 "readability-container-data-pointer");
87 "readability-container-size-empty");
89 "readability-convert-member-functions-to-static");
91 "readability-delete-null-pointer");
93 "readability-duplicate-include");
94 CheckFactories.registerCheck<ElseAfterReturnCheck>(
95 "readability-else-after-return");
97 "readability-enum-initial-value");
99 "readability-function-cognitive-complexity");
100 CheckFactories.registerCheck<FunctionSizeCheck>(
101 "readability-function-size");
102 CheckFactories.registerCheck<IdentifierLengthCheck>(
103 "readability-identifier-length");
104 CheckFactories.registerCheck<IdentifierNamingCheck>(
105 "readability-identifier-naming");
107 "readability-implicit-bool-conversion");
109 "readability-redundant-inline-specifier");
111 "readability-inconsistent-declaration-parameter-name");
113 "readability-isolate-declaration");
114 CheckFactories.registerCheck<MagicNumbersCheck>(
115 "readability-magic-numbers");
117 "readability-make-member-function-const");
119 "readability-misleading-indentation");
121 "readability-misplaced-array-index");
123 "readability-operators-representation");
124 CheckFactories.registerCheck<QualifiedAutoCheck>(
125 "readability-qualified-auto");
127 "readability-redundant-access-specifiers");
128 CheckFactories.registerCheck<RedundantCastingCheck>(
129 "readability-redundant-casting");
131 "readability-redundant-function-ptr-dereference");
133 "readability-redundant-member-init");
135 "readability-redundant-preprocessor");
137 "readability-reference-to-constructed-temporary");
139 "readability-simplify-subscript-expr");
141 "readability-static-accessed-through-instance");
143 "readability-static-definition-in-anonymous-namespace");
144 CheckFactories.registerCheck<StringCompareCheck>(
145 "readability-string-compare");
147 "readability-named-parameter");
149 "readability-non-const-parameter");
151 "readability-redundant-control-flow");
153 "readability-redundant-declaration");
155 "readability-redundant-smartptr-get");
157 "readability-redundant-string-cstr");
159 "readability-redundant-string-init");
161 "readability-simplify-boolean-expr");
163 "readability-suspicious-call-argument");
165 "readability-uniqueptr-delete-release");
167 "readability-uppercase-literal-suffix");
168 CheckFactories.registerCheck<UseAnyOfAllOfCheck>(
169 "readability-use-anyofallof");
170 CheckFactories.registerCheck<UseStdMinMaxCheck>(
171 "readability-use-std-min-max");
172 }
173};
174
175// Register the ReadabilityModule using this statically initialized variable.
176static ClangTidyModuleRegistry::Add<ReadabilityModule>
177 X("readability-module", "Adds readability-related checks.");
178
179} // namespace readability
180
181// This anchor is used to force the linker to link in the generated object file
182// and thus register the ReadabilityModule.
184
185} // namespace clang::tidy
int X
A collection of ClangTidyCheckFactory instances.
void registerCheck(llvm::StringRef CheckName)
Registers the CheckType with the name Name.
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Identifies instances of nested conditional operators in the code.
Finds return statements with void values used within functions with void result types.
Finds code blocks that are constantly enabled or disabled in preprocessor directives by analyzing #if...
Checks that bodies of if statements and loops (for, range-for, do-while, and while) are inside braces...
For any function whose return type is const-qualified, suggests removal of the const qualifier from t...
Finds usages of container.count() and find() == end() which should be replaced by a call to the conta...
Checks whether a call to operator[] and & can be replaced with a call to data().
Checks whether a call to the size()/length() method can be replaced with a call to empty().
This check finds C++ class methods than can be made static because they don't use the 'this' pointer.
Check whether the 'if' statement is unnecessary before calling 'delete' on a pointer.
Find and remove duplicate #include directives.
Flags the usages of else after return.
Enforces consistent style for enumerators' initialization, covering three styles: none,...
Checks for large functions based on various metrics.
Warns about identifiers names whose length is too short.
Checks for identifiers naming style mismatch.
Checks for use of implicit bool conversions in expressions.
Checks for declarations of functions which differ in parameter names.
This check diagnoses all DeclStmt's declaring more than one variable and tries to refactor the code t...
Detects magic numbers, integer and floating point literals embedded in code.
Finds non-static member functions that can be made 'const'.
Checks the code for dangling else, and possible misleading indentations due to missing braces.
Warn about unusual array index syntax (index[array] instead of array[index]).
Find functions with unnamed arguments.
Warn when a pointer function parameter can be const.
Enforces consistent token representation for invoked binary, unary and overloaded operators in C++ co...
Finds variables declared as auto that could be declared as: 'auto*' or 'const auto *' and reference v...
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module.
Detects redundant access specifiers inside classes, structs, and unions.
Detects explicit type casting operations that involve the same source and destination types,...
Eliminates redundant return statements at the end of a function that returns void.
Detects redundant inline specifiers on function and variable declarations.
Finds member initializations that are unnecessary because the same default constructor would be calle...
This check flags redundant preprocessor directives: nested directives with the same condition.
Find and remove redundant calls to smart pointer's .get() method.
Finds unnecessary calls to std::string::c_str().
Finds unnecessary string initializations.
Detects C++ code where a reference variable is used to extend the lifetime of a temporary object that...
Looks for boolean expressions involving boolean constants and simplifies them to use the appropriate ...
Checks for member expressions that access static members through instances and replaces them with use...
Finds static function and variable definitions in anonymous namespace.
This check flags all calls compare when used to check for string equality or inequality.
Finds function calls where the arguments passed are provided out of order, based on the difference be...
Flags statements of the form delete <unique_ptr expr>.release(); and replaces them with: <unique_ptr ...
Detects when the integral literal or floating point literal has non-uppercase suffix,...
Finds ranged-based for loops that can be replaced by a call to std::any_of or std::all_of.
Replaces certain conditional statements with equivalent calls to std::min or std::max.
volatile int ReadabilityModuleAnchorSource