[PATCH] D43581: [clang-tidy/google] Fix the Objective-C global variable declaration check 🔧
Stephane Moore via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 22 12:13:34 PST 2018
stephanemoore updated this revision to Diff 135497.
stephanemoore added a comment.
Update the diagnostic information to link to the Google Objective-C style guide for guidance on an appropriate prefix.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D43581
Files:
clang-tidy/google/GlobalVariableDeclarationCheck.cpp
test/clang-tidy/google-objc-global-variable-declaration.m
Index: test/clang-tidy/google-objc-global-variable-declaration.m
===================================================================
--- test/clang-tidy/google-objc-global-variable-declaration.m
+++ test/clang-tidy/google-objc-global-variable-declaration.m
@@ -30,8 +30,16 @@
// CHECK-FIXES: static NSString* const k_Alpha = @"SecondNotAlpha";
static NSString* const kGood = @"hello";
+static NSString* const XYGood = @"hello";
static NSString* gMyIntGood = 0;
+extern NSString* const GTLServiceErrorDomain;
+
+typedef NS_ENUM(NSInteger, GTLServiceError) {
+ GTLServiceErrorQueryResultMissing = -3000,
+ GTLServiceErrorWaitTimedOut = -3001,
+};
+
@implementation Foo
- (void)f {
int x = 0;
Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===================================================================
--- clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -72,7 +72,7 @@
this);
Finder->addMatcher(varDecl(hasGlobalStorage(), hasType(isConstQualified()),
unless(isLocalVariable()),
- unless(matchesName("::k[A-Z]")))
+ unless(matchesName("::(k[A-Z]|[A-Z]{2,})")))
.bind("global_const"),
this);
}
@@ -88,7 +88,8 @@
if (const auto *Decl = Result.Nodes.getNodeAs<VarDecl>("global_const")) {
diag(Decl->getLocation(),
"const global variable '%0' must have a name which starts with "
- "'k[A-Z]'")
+ "an appropriate prefix (see "
+ "http://google.github.io/styleguide/objcguide#constants).")
<< Decl->getName() << generateFixItHint(Decl, true);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43581.135497.patch
Type: text/x-patch
Size: 1744 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180222/af9c31af/attachment.bin>
More information about the cfe-commits
mailing list