clang-tools 20.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"
38#include "NamedParameterCheck.h"
41#include "QualifiedAutoCheck.h"
58#include "StringCompareCheck.h"
62#include "UseAnyOfAllOfCheck.h"
63#include "UseStdMinMaxCheck.h"
64
65namespace clang::tidy {
66namespace readability {
67
69public:
70 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
72 "readability-avoid-const-params-in-decls");
74 "readability-avoid-nested-conditional-operator");
76 "readability-avoid-return-with-void-value");
78 "readability-avoid-unconditional-preprocessor-if");
80 "readability-braces-around-statements");
81 CheckFactories.registerCheck<ConstReturnTypeCheck>(
82 "readability-const-return-type");
84 "readability-container-contains");
86 "readability-container-data-pointer");
88 "readability-container-size-empty");
90 "readability-convert-member-functions-to-static");
92 "readability-delete-null-pointer");
94 "readability-duplicate-include");
95 CheckFactories.registerCheck<ElseAfterReturnCheck>(
96 "readability-else-after-return");
98 "readability-enum-initial-value");
100 "readability-function-cognitive-complexity");
101 CheckFactories.registerCheck<FunctionSizeCheck>(
102 "readability-function-size");
103 CheckFactories.registerCheck<IdentifierLengthCheck>(
104 "readability-identifier-length");
105 CheckFactories.registerCheck<IdentifierNamingCheck>(
106 "readability-identifier-naming");
108 "readability-implicit-bool-conversion");
110 "readability-math-missing-parentheses");
112 "readability-redundant-inline-specifier");
114 "readability-inconsistent-declaration-parameter-name");
116 "readability-isolate-declaration");
117 CheckFactories.registerCheck<MagicNumbersCheck>(
118 "readability-magic-numbers");
120 "readability-make-member-function-const");
122 "readability-misleading-indentation");
124 "readability-misplaced-array-index");
126 "readability-operators-representation");
127 CheckFactories.registerCheck<QualifiedAutoCheck>(
128 "readability-qualified-auto");
130 "readability-redundant-access-specifiers");
131 CheckFactories.registerCheck<RedundantCastingCheck>(
132 "readability-redundant-casting");
134 "readability-redundant-function-ptr-dereference");
136 "readability-redundant-member-init");
138 "readability-redundant-preprocessor");
140 "readability-reference-to-constructed-temporary");
142 "readability-simplify-subscript-expr");
144 "readability-static-accessed-through-instance");
146 "readability-static-definition-in-anonymous-namespace");
147 CheckFactories.registerCheck<StringCompareCheck>(
148 "readability-string-compare");
150 "readability-named-parameter");
152 "readability-non-const-parameter");
154 "readability-redundant-control-flow");
156 "readability-redundant-declaration");
158 "readability-redundant-smartptr-get");
160 "readability-redundant-string-cstr");
162 "readability-redundant-string-init");
164 "readability-simplify-boolean-expr");
166 "readability-suspicious-call-argument");
168 "readability-uniqueptr-delete-release");
170 "readability-uppercase-literal-suffix");
171 CheckFactories.registerCheck<UseAnyOfAllOfCheck>(
172 "readability-use-anyofallof");
173 CheckFactories.registerCheck<UseStdMinMaxCheck>(
174 "readability-use-std-min-max");
175 }
176};
177
178// Register the ReadabilityModule using this statically initialized variable.
179static ClangTidyModuleRegistry::Add<ReadabilityModule>
180 X("readability-module", "Adds readability-related checks.");
181
182} // namespace readability
183
184// This anchor is used to force the linker to link in the generated object file
185// and thus register the ReadabilityModule.
187
188} // 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 container.find() == container.end() which should be replaced by...
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'.
Check for mising parantheses in mathematical expressions that involve operators of different prioriti...
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