[PATCH] D49285: [clang-tidy] readability-inconsistent-declaration-parameter-name: accept approximate name matches.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 13 02:58:22 PDT 2018
sammccall created this revision.
Herald added subscribers: cfe-commits, xazax.hun.
The goal is to reduce false positives when the difference is intentional, like:
foo(StringRef name);
foo(StringRef name_ref) {
string name = cleanup(name_ref);
...
}
Or semantically unimportant, like:
foo(StringRef full_name);
foo(StringRef name) { ... }
There are other matching names we won't recognise (e.g. syns vs synonyms) but
this catches many that we see in practice, and gives people a systematic
workaround.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D49285
Files:
clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp
Index: test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp
===================================================================
--- test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp
+++ test/clang-tidy/readability-inconsistent-declaration-parameter-name.cpp
@@ -2,6 +2,8 @@
void consistentFunction(int a, int b, int c);
void consistentFunction(int a, int b, int c);
+void consistentFunction(int prefixA, int inBFix, int cSuffix);
+void consistentFunction(int a, int b, int c);
void consistentFunction(int a, int b, int /*c*/);
void consistentFunction(int /*c*/, int /*c*/, int /*c*/);
Index: clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
===================================================================
--- clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
+++ clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
@@ -90,6 +90,12 @@
return true;
}
+// We allow two names if one is a substring of the other, ignoring case.
+// Important special case: this is true if either parameter has no name!
+bool nameMatch(StringRef L, StringRef R) {
+ return L.contains_lower(R) || R.contains_lower(L);
+}
+
DifferingParamsContainer
findDifferingParamsInDeclaration(const FunctionDecl *ParameterSourceDeclaration,
const FunctionDecl *OtherDeclaration,
@@ -106,8 +112,7 @@
// FIXME: Provide a way to extract commented out parameter name from comment
// next to it.
- if (!SourceParamName.empty() && !OtherParamName.empty() &&
- SourceParamName != OtherParamName) {
+ if (!nameMatch(SourceParamName, OtherParamName)) {
SourceRange OtherParamNameRange =
DeclarationNameInfo((*OtherParamIt)->getDeclName(),
(*OtherParamIt)->getLocation())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49285.155337.patch
Type: text/x-patch
Size: 1852 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180713/ea0964a2/attachment-0001.bin>
More information about the cfe-commits
mailing list