summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/google
diff options
context:
space:
mode:
authorStephane Moore <mog@google.com>2019-05-29 01:36:23 +0000
committerStephane Moore <mog@google.com>2019-05-29 01:36:23 +0000
commit12e3726fadb0b2a4d8aeed0a2817b5159f9d029d (patch)
treee74dd7f6bcf979dc80bc637ca44e58dd7969bd3f /clang-tools-extra/clang-tidy/google
parent860736cc3cfc60a15012d754be41aa389898a1e6 (diff)
downloadbcm5719-llvm-12e3726fadb0b2a4d8aeed0a2817b5159f9d029d.tar.gz
bcm5719-llvm-12e3726fadb0b2a4d8aeed0a2817b5159f9d029d.zip
Revise the google-objc-global-variable-declaration check to match the style guide.
Summary: Revise the google-objc-global-variable-declaration check to match the style guide. This commit updates the check as follows: (1) Do not emit fixes for extern global constants. (2) Allow the second character of prefixes for constants to be numeric (the new guideline is that global constants should generally be named with a prefix that begins with a capital letter followed by one or more capital letters or numbers). https://google.github.io/styleguide/objcguide.html#prefixes Contributed by yaqiji. Reviewers: Wizard, benhamilton, stephanemoore Reviewed By: benhamilton, stephanemoore Subscribers: mgorny, cfe-commits, yaqiji Tags: #clang Differential Revision: https://reviews.llvm.org/D62045 llvm-svn: 361907
Diffstat (limited to 'clang-tools-extra/clang-tidy/google')
-rw-r--r--clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp b/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
index ce833906dd5..30ab04c08c0 100644
--- a/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -23,29 +23,35 @@ namespace objc {
namespace {
-AST_MATCHER(VarDecl, isLocalVariable) {
- return Node.isLocalVarDecl();
-}
+AST_MATCHER(VarDecl, isLocalVariable) { return Node.isLocalVarDecl(); }
FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
+ if (IsConst && (Decl->getStorageClass() != SC_Static)) {
+ // No fix available if it is not a static constant, since it is difficult
+ // to determine the proper fix in this case.
+ return FixItHint();
+ }
+
char FC = Decl->getName()[0];
if (!llvm::isAlpha(FC) || Decl->getName().size() == 1) {
// No fix available if first character is not alphabetical character, or it
- // is a single-character variable, since it is difficult to determine the
+ // is a single-character variable, since it is difficult to determine the
// proper fix in this case. Users should create a proper variable name by
// their own.
return FixItHint();
}
char SC = Decl->getName()[1];
if ((FC == 'k' || FC == 'g') && !llvm::isAlpha(SC)) {
- // No fix available if the prefix is correct but the second character is not
- // alphabetical, since it is difficult to determine the proper fix in this
- // case.
+ // No fix available if the prefix is correct but the second character is
+ // not alphabetical, since it is difficult to determine the proper fix in
+ // this case.
return FixItHint();
}
+
auto NewName = (IsConst ? "k" : "g") +
llvm::StringRef(std::string(1, FC)).upper() +
Decl->getName().substr(1).str();
+
return FixItHint::CreateReplacement(
CharSourceRange::getTokenRange(SourceRange(Decl->getLocation())),
llvm::StringRef(NewName));
@@ -71,7 +77,7 @@ void GlobalVariableDeclarationCheck::registerMatchers(MatchFinder *Finder) {
this);
Finder->addMatcher(varDecl(hasGlobalStorage(), hasType(isConstQualified()),
unless(isLocalVariable()),
- unless(matchesName("::(k[A-Z]|[A-Z]{2,})")))
+ unless(matchesName("::(k[A-Z])|([A-Z][A-Z0-9])")))
.bind("global_const"),
this);
}
OpenPOWER on IntegriCloud