clang-tools 10.0.0

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"
12 #include "AvoidConstParamsInDecls.h"
13 #include "BracesAroundStatementsCheck.h"
14 #include "ConstReturnTypeCheck.h"
15 #include "ContainerSizeEmptyCheck.h"
16 #include "ConvertMemberFunctionsToStatic.h"
17 #include "DeleteNullPointerCheck.h"
18 #include "DeletedDefaultCheck.h"
19 #include "ElseAfterReturnCheck.h"
20 #include "FunctionSizeCheck.h"
21 #include "IdentifierNamingCheck.h"
22 #include "ImplicitBoolConversionCheck.h"
23 #include "InconsistentDeclarationParameterNameCheck.h"
24 #include "IsolateDeclarationCheck.h"
25 #include "MagicNumbersCheck.h"
26 #include "MakeMemberFunctionConstCheck.h"
27 #include "MisleadingIndentationCheck.h"
28 #include "MisplacedArrayIndexCheck.h"
29 #include "NamedParameterCheck.h"
30 #include "NonConstParameterCheck.h"
31 #include "QualifiedAutoCheck.h"
32 #include "RedundantAccessSpecifiersCheck.h"
33 #include "RedundantControlFlowCheck.h"
34 #include "RedundantDeclarationCheck.h"
35 #include "RedundantFunctionPtrDereferenceCheck.h"
36 #include "RedundantMemberInitCheck.h"
37 #include "RedundantPreprocessorCheck.h"
38 #include "RedundantSmartptrGetCheck.h"
39 #include "RedundantStringCStrCheck.h"
40 #include "RedundantStringInitCheck.h"
41 #include "SimplifyBooleanExprCheck.h"
42 #include "SimplifySubscriptExprCheck.h"
43 #include "StaticAccessedThroughInstanceCheck.h"
44 #include "StaticDefinitionInAnonymousNamespaceCheck.h"
45 #include "StringCompareCheck.h"
46 #include "UniqueptrDeleteReleaseCheck.h"
47 #include "UppercaseLiteralSuffixCheck.h"
48
49 namespace clang {
50 namespace tidy {
51 namespace readability {
52
53 class ReadabilityModule : public ClangTidyModule {
54 public:
55 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
56 CheckFactories.registerCheck<AvoidConstParamsInDecls>(
57 "readability-avoid-const-params-in-decls");
58 CheckFactories.registerCheck<BracesAroundStatementsCheck>(
59 "readability-braces-around-statements");
60 CheckFactories.registerCheck<ConstReturnTypeCheck>(
61 "readability-const-return-type");
62 CheckFactories.registerCheck<ContainerSizeEmptyCheck>(
63 "readability-container-size-empty");
64 CheckFactories.registerCheck<ConvertMemberFunctionsToStatic>(
65 "readability-convert-member-functions-to-static");
66 CheckFactories.registerCheck<DeleteNullPointerCheck>(
67 "readability-delete-null-pointer");
68 CheckFactories.registerCheck<DeletedDefaultCheck>(
69 "readability-deleted-default");
70 CheckFactories.registerCheck<ElseAfterReturnCheck>(
71 "readability-else-after-return");
72 CheckFactories.registerCheck<FunctionSizeCheck>(
73 "readability-function-size");
74 CheckFactories.registerCheck<IdentifierNamingCheck>(
75 "readability-identifier-naming");
76 CheckFactories.registerCheck<ImplicitBoolConversionCheck>(
77 "readability-implicit-bool-conversion");
78 CheckFactories.registerCheck<InconsistentDeclarationParameterNameCheck>(
79 "readability-inconsistent-declaration-parameter-name");
80 CheckFactories.registerCheck<IsolateDeclarationCheck>(
81 "readability-isolate-declaration");
82 CheckFactories.registerCheck<MagicNumbersCheck>(
83 "readability-magic-numbers");
84 CheckFactories.registerCheck<MakeMemberFunctionConstCheck>(
85 "readability-make-member-function-const");
86 CheckFactories.registerCheck<MisleadingIndentationCheck>(
87 "readability-misleading-indentation");
88 CheckFactories.registerCheck<MisplacedArrayIndexCheck>(
89 "readability-misplaced-array-index");
90 CheckFactories.registerCheck<QualifiedAutoCheck>(
91 "readability-qualified-auto");
92 CheckFactories.registerCheck<RedundantAccessSpecifiersCheck>(
93 "readability-redundant-access-specifiers");
94 CheckFactories.registerCheck<RedundantFunctionPtrDereferenceCheck>(
95 "readability-redundant-function-ptr-dereference");
96 CheckFactories.registerCheck<RedundantMemberInitCheck>(
97 "readability-redundant-member-init");
98 CheckFactories.registerCheck<RedundantPreprocessorCheck>(
99 "readability-redundant-preprocessor");
100 CheckFactories.registerCheck<SimplifySubscriptExprCheck>(
101 "readability-simplify-subscript-expr");
102 CheckFactories.registerCheck<StaticAccessedThroughInstanceCheck>(
103 "readability-static-accessed-through-instance");
104 CheckFactories.registerCheck<StaticDefinitionInAnonymousNamespaceCheck>(
105 "readability-static-definition-in-anonymous-namespace");
106 CheckFactories.registerCheck<StringCompareCheck>(
107 "readability-string-compare");
108 CheckFactories.registerCheck<readability::NamedParameterCheck>(
109 "readability-named-parameter");
110 CheckFactories.registerCheck<NonConstParameterCheck>(
111 "readability-non-const-parameter");
112 CheckFactories.registerCheck<RedundantControlFlowCheck>(
113 "readability-redundant-control-flow");
114 CheckFactories.registerCheck<RedundantDeclarationCheck>(
115 "readability-redundant-declaration");
116 CheckFactories.registerCheck<RedundantSmartptrGetCheck>(
117 "readability-redundant-smartptr-get");
118 CheckFactories.registerCheck<RedundantStringCStrCheck>(
119 "readability-redundant-string-cstr");
120 CheckFactories.registerCheck<RedundantStringInitCheck>(
121 "readability-redundant-string-init");
122 CheckFactories.registerCheck<SimplifyBooleanExprCheck>(
123 "readability-simplify-boolean-expr");
124 CheckFactories.registerCheck<UniqueptrDeleteReleaseCheck>(
125 "readability-uniqueptr-delete-release");
126 CheckFactories.registerCheck<UppercaseLiteralSuffixCheck>(
127 "readability-uppercase-literal-suffix");
128 }
129 };
130
131 // Register the ReadabilityModule using this statically initialized variable.
132 static ClangTidyModuleRegistry::Add<ReadabilityModule>
133 X("readability-module", "Adds readability-related checks.");
134
135 } // namespace readability
136
137 // This anchor is used to force the linker to link in the generated object file
138 // and thus register the ReadabilityModule.
139 volatile int ReadabilityModuleAnchorSource = 0;
140
141 } // namespace tidy
142 } // namespace clang
MisleadingIndentationCheck.h
clang::tidy::readability::QualifiedAutoCheck
Finds variables declared as auto that could be declared as: &#39;auto*&#39; or &#39;const auto *&#39; and reference v...
Definition: QualifiedAutoCheck.h:24
MisplacedArrayIndexCheck.h
clang::tidy::readability::UppercaseLiteralSuffixCheck
Detects when the integral literal or floating point literal has non-uppercase suffix, and suggests to make the suffix uppercase.
Definition: UppercaseLiteralSuffixCheck.h:25
clang::tidy::ReadabilityModuleAnchorSource
volatile int ReadabilityModuleAnchorSource
Definition: ReadabilityTidyModule.cpp:139
clang::tidy::readability::RedundantMemberInitCheck
Finds member initializations that are unnecessary because the same default constructor would be calle...
Definition: RedundantMemberInitCheck.h:23
clang::tidy::readability::DeletedDefaultCheck
Checks when a constructor or an assignment operator is marked as &#39;= default&#39; but is actually deleted ...
Definition: DeletedDefaultCheck.h:23
NonConstParameterCheck.h
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:58
RedundantControlFlowCheck.h
InconsistentDeclarationParameterNameCheck.h
SimplifyBooleanExprCheck.h
QualifiedAutoCheck.h
clang::tidy::readability::StaticDefinitionInAnonymousNamespaceCheck
Finds static function and variable definitions in anonymous namespace.
Definition: StaticDefinitionInAnonymousNamespaceCheck.h:22
clang::tidy::readability::DeleteNullPointerCheck
Check whether the &#39;if&#39; statement is unnecessary before calling &#39;delete&#39; on a pointer.
Definition: DeleteNullPointerCheck.h:23
clang::tidy::readability::SimplifyBooleanExprCheck
Looks for boolean expressions involving boolean constants and simplifies them to use the appropriate ...
Definition: SimplifyBooleanExprCheck.h:23
MakeMemberFunctionConstCheck.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
clang::tidy::ClangTidyCheckFactories
A collection of ClangTidyCheckFactory instances.
Definition: ClangTidyModule.h:27
clang::tidy::readability::ReadabilityModule
Definition: ReadabilityTidyModule.cpp:53
UniqueptrDeleteReleaseCheck.h
clang::tidy::readability::MakeMemberFunctionConstCheck
Finds non-static member functions that can be made &#39;const&#39;.
Definition: MakeMemberFunctionConstCheck.h:22
clang::tidy::readability::ElseAfterReturnCheck
Flags the usages of else after return.
Definition: ElseAfterReturnCheck.h:21
clang::tidy::readability::X
static ClangTidyModuleRegistry::Add< ReadabilityModule > X("readability-module", "Adds readability-related checks.")
clang::tidy::readability::IsolateDeclarationCheck
This check diagnoses all DeclStmt&#39;s declaring more than one variable and tries to refactor the code t...
Definition: IsolateDeclarationCheck.h:23
RedundantStringCStrCheck.h
clang::tidy::readability::FunctionSizeCheck
Checks for large functions based on various metrics.
Definition: FunctionSizeCheck.h:37
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:80
SimplifySubscriptExprCheck.h
RedundantAccessSpecifiersCheck.h
DeletedDefaultCheck.h
clang::tidy::readability::NonConstParameterCheck
Warn when a pointer function parameter can be const.
Definition: NonConstParameterCheck.h:22
clang::tidy::readability::MagicNumbersCheck
Detects magic numbers, integer and floating point literals embedded in code.
Definition: MagicNumbersCheck.h:25
clang::tidy::readability::SimplifySubscriptExprCheck
Simplifies subscript expressions.
Definition: SimplifySubscriptExprCheck.h:22
clang::tidy::readability::RedundantPreprocessorCheck
This check flags redundant preprocessor directives: nested directives with the same condition...
Definition: RedundantPreprocessorCheck.h:23
clang::tidy::readability::RedundantStringInitCheck
Finds unnecessary string initializations.
Definition: RedundantStringInitCheck.h:21
clang::tidy::readability::RedundantSmartptrGetCheck
Find and remove redundant calls to smart pointer&#39;s .get() method.
Definition: RedundantSmartptrGetCheck.h:27
clang::tidy::readability::MisplacedArrayIndexCheck
Warn about unusual array index syntax (index[array] instead of array[index]).
Definition: MisplacedArrayIndexCheck.h:23
RedundantFunctionPtrDereferenceCheck.h
clang::tidy::readability::StaticAccessedThroughInstanceCheck
Checks for member expressions that access static members through instances and replaces them with use...
Definition: StaticAccessedThroughInstanceCheck.h:23
ElseAfterReturnCheck.h
clang::tidy::readability::ConvertMemberFunctionsToStatic
This check finds C++ class methods than can be made static because they don&#39;t use the &#39;this&#39; pointer...
Definition: ConvertMemberFunctionsToStatic.h:25
NamedParameterCheck.h
StringCompareCheck.h
RedundantMemberInitCheck.h
BracesAroundStatementsCheck.h
ImplicitBoolConversionCheck.h
StaticDefinitionInAnonymousNamespaceCheck.h
RedundantSmartptrGetCheck.h
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
IdentifierNamingCheck.h
clang::tidy::readability::ImplicitBoolConversionCheck
Checks for use of implicit bool conversions in expressions.
Definition: ImplicitBoolConversionCheck.h:22
clang::tidy::readability::AvoidConstParamsInDecls
Definition: AvoidConstParamsInDecls.h:20
DeleteNullPointerCheck.h
clang::tidy::readability::InconsistentDeclarationParameterNameCheck
Checks for declarations of functions which differ in parameter names.
Definition: InconsistentDeclarationParameterNameCheck.h:25
clang::tidy::readability::RedundantAccessSpecifiersCheck
Detects redundant access specifiers inside classes, structs, and unions.
Definition: RedundantAccessSpecifiersCheck.h:22
clang::tidy::readability::NamedParameterCheck
Find functions with unnamed arguments.
Definition: NamedParameterCheck.h:29
clang::tidy::readability::StringCompareCheck
This check flags all calls compare when used to check for string equality or inequality.
Definition: StringCompareCheck.h:23
RedundantDeclarationCheck.h
IsolateDeclarationCheck.h
UppercaseLiteralSuffixCheck.h
clang::tidy::readability::UniqueptrDeleteReleaseCheck
Flags statements of the form delete <unique_ptr expr>.release(); and replaces them with: <unique_ptr ...
Definition: UniqueptrDeleteReleaseCheck.h:23
AvoidConstParamsInDecls.h
clang::tidy::readability::RedundantStringCStrCheck
Finds unnecessary calls to std::string::c_str().
Definition: RedundantStringCStrCheck.h:19
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
FunctionSizeCheck.h
clang::tidy::readability::MisleadingIndentationCheck
Checks the code for dangling else, and possible misleading indentations due to missing braces...
Definition: MisleadingIndentationCheck.h:24
clang::tidy::readability::RedundantDeclarationCheck
Find redundant variable declarations.
Definition: RedundantDeclarationCheck.h:22
MagicNumbersCheck.h
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:55
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
clang::tidy::readability::RedundantControlFlowCheck
Eliminates redundant return statements at the end of a function that returns void.
Definition: RedundantControlFlowCheck.h:25
ConvertMemberFunctionsToStatic.h
RedundantStringInitCheck.h
ConstReturnTypeCheck.h
clang::tidy::readability::RedundantFunctionPtrDereferenceCheck
Eliminate redundant dereferences of a function pointer.
Definition: RedundantFunctionPtrDereferenceCheck.h:22
StaticAccessedThroughInstanceCheck.h
clang::tidy::readability::IdentifierNamingCheck
Checks for identifiers naming style mismatch.
Definition: IdentifierNamingCheck.h:34
ContainerSizeEmptyCheck.h
RedundantPreprocessorCheck.h