[PATCH] D42261: [clang-tidy objc-property-declaration] New option AdditionalAcronyms
Ben Hamilton via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 18 12:52:58 PST 2018
benhamilton created this revision.
benhamilton added reviewers: Wizard, hokein, klimek.
Herald added a subscriber: cfe-commits.
The existing option objc-property-declaration.Acronyms
replaces the built-in set of acronyms.
While this behavior is OK for clients that don't want the default
behavior, many clients may just want to add their own custom acronyms
to the default list.
This revision introduces a new option,
objc-property-declaration.AdditionalAcronyms, which appends custom
acronyms to the default list (instead of replacing the default list).
I also updated the documentation.
Test Plan: make -j12 check-clang-tools
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D42261
Files:
clang-tidy/objc/PropertyDeclarationCheck.cpp
clang-tidy/objc/PropertyDeclarationCheck.h
docs/clang-tidy/checks/objc-property-declaration.rst
test/clang-tidy/objc-property-declaration-additional.m
test/clang-tidy/objc-property-declaration-custom.m
Index: test/clang-tidy/objc-property-declaration-custom.m
===================================================================
--- test/clang-tidy/objc-property-declaration-custom.m
+++ test/clang-tidy/objc-property-declaration-custom.m
@@ -11,4 +11,6 @@
@property(assign, nonatomic) int ABCCustomPrefix;
@property(strong, nonatomic) NSString *ABC_custom_prefix;
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'ABC_custom_prefix' should use lowerCamelCase style, according to the Apple Coding Guidelines [objc-property-declaration]
+ at property(assign, nonatomic) int GIFIgnoreStandardAcronym;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'GIFIgnoreStandardAcronym' should use lowerCamelCase style, according to the Apple Coding Guidelines [objc-property-declaration]
@end
Index: test/clang-tidy/objc-property-declaration-additional.m
===================================================================
--- test/clang-tidy/objc-property-declaration-additional.m
+++ test/clang-tidy/objc-property-declaration-additional.m
@@ -1,6 +1,6 @@
// RUN: %check_clang_tidy %s objc-property-declaration %t \
// RUN: -config='{CheckOptions: \
-// RUN: [{key: objc-property-declaration.Acronyms, value: "ABC;TGIF"}]}' \
+// RUN: [{key: objc-property-declaration.AdditionalAcronyms, value: "ABC;TGIF"}]}' \
// RUN: --
@class NSString;
@@ -11,4 +11,5 @@
@property(assign, nonatomic) int ABCCustomPrefix;
@property(strong, nonatomic) NSString *ABC_custom_prefix;
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'ABC_custom_prefix' should use lowerCamelCase style, according to the Apple Coding Guidelines [objc-property-declaration]
+ at property(assign, nonatomic) int GIFShouldIncludeStandardAcronym;
@end
Index: docs/clang-tidy/checks/objc-property-declaration.rst
===================================================================
--- docs/clang-tidy/checks/objc-property-declaration.rst
+++ docs/clang-tidy/checks/objc-property-declaration.rst
@@ -41,3 +41,12 @@
or a suffix of property names.
If unset, defaults to "ACL;API;ARGB;ASCII;BGRA;CMYK;DNS;FPS;FTP;GIF;GPS;HD;HDR;HTML;HTTP;HTTPS;HUD;ID;JPG;JS;LAN;LZW;MDNS;MIDI;OS;PDF;PIN;PNG;POI;PSTN;PTR;QA;QOS;RGB;RGBA;RGBX;ROM;RPC;RTF;RTL;SDK;SSO;TCP;TIFF;TTS;UI;URI;URL;VC;VOIP;VPN;VR;WAN;XML".
+
+ If set, replaces the default list. (If you want to append to the default list, set AdditionalAcronyms instead.)
+
+.. option:: AdditionalAcronyms
+
+ Semicolon-separated list of additional acronyms that can be used as a prefix
+ or a suffix of property names.
+
+ Appends to the list in Acronyms.
Index: clang-tidy/objc/PropertyDeclarationCheck.h
===================================================================
--- clang-tidy/objc/PropertyDeclarationCheck.h
+++ clang-tidy/objc/PropertyDeclarationCheck.h
@@ -35,6 +35,7 @@
private:
const std::vector<std::string> SpecialAcronyms;
+ const std::vector<std::string> AdditionalAcronyms;
};
} // namespace objc
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===================================================================
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -124,14 +124,22 @@
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
SpecialAcronyms(utils::options::parseStringList(
- Options.get("Acronyms", DefaultSpecialAcronyms))) {}
+ Options.get("Acronyms", DefaultSpecialAcronyms))),
+ AdditionalAcronyms(utils::options::parseStringList(
+ Options.get("AdditionalAcronyms", ""))) {}
void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) {
+ std::vector<std::string> Acronyms;
+ Acronyms.reserve(SpecialAcronyms.size() + AdditionalAcronyms.size());
+ Acronyms.insert(Acronyms.end(), SpecialAcronyms.begin(),
+ SpecialAcronyms.end());
+ Acronyms.insert(Acronyms.end(), AdditionalAcronyms.begin(),
+ AdditionalAcronyms.end());
Finder->addMatcher(
objcPropertyDecl(
// the property name should be in Lower Camel Case like
// 'lowerCamelCase'
- unless(matchesName(validPropertyNameRegex(SpecialAcronyms))))
+ unless(matchesName(validPropertyNameRegex(Acronyms))))
.bind("property"),
this);
}
@@ -149,6 +157,8 @@
void PropertyDeclarationCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "Acronyms",
utils::options::serializeStringList(SpecialAcronyms));
+ Options.store(Opts, "AdditionalAcronyms",
+ utils::options::serializeStringList(AdditionalAcronyms));
}
} // namespace objc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42261.130479.patch
Type: text/x-patch
Size: 4715 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180118/487bf4e7/attachment.bin>
More information about the cfe-commits
mailing list