[clang-tools-extra] r330492 - [clang-tidy] add new check to find out objc ivars which do not have prefix '_'
Yan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 20 16:18:09 PDT 2018
Author: wizard
Date: Fri Apr 20 16:18:09 2018
New Revision: 330492
URL: http://llvm.org/viewvc/llvm-project?rev=330492&view=rev
Log:
[clang-tidy] add new check to find out objc ivars which do not have prefix '_'
Summary:
For code of ivar declaration:
int barWithoutPrefix;
The fix will be:
int _barWithoutPrefix;
Reviewers: benhamilton, hokein, alexfh, aaron.ballman, ilya-biryukov
Reviewed By: alexfh
Subscribers: Eugene.Zelenko, xazax.hun, klimek, mgorny, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D45392
Added:
clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
Modified:
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
Modified: clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp?rev=330492&r1=330491&r2=330492&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp Fri Apr 20 16:18:09 2018
@@ -109,6 +109,7 @@ namespace readability {
m(TemplateParameter) \
m(TypeAlias) \
m(MacroDefinition) \
+ m(ObjcIvar) \
enum StyleKind {
#define ENUMERATE(v) SK_ ## v,
@@ -384,6 +385,9 @@ static StyleKind findStyleKind(
const NamedDecl *D,
const std::vector<llvm::Optional<IdentifierNamingCheck::NamingStyle>>
&NamingStyles) {
+ if (isa<ObjCIvarDecl>(D) && NamingStyles[SK_ObjcIvar])
+ return SK_ObjcIvar;
+
if (isa<TypedefDecl>(D) && NamingStyles[SK_Typedef])
return SK_Typedef;
Added: clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m?rev=330492&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m (added)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming-objc.m Fri Apr 20 16:18:09 2018
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t \
+// RUN: -config='{CheckOptions: \
+// RUN: [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
+// RUN: --
+
+ at interface Foo
+ at end
+
+ at interface Foo () {
+ int _bar;
+ int barWithoutPrefix;
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for objc ivar 'barWithoutPrefix' [readability-identifier-naming]
+ // CHECK-FIXES: int _barWithoutPrefix;
+}
+ at end
More information about the cfe-commits
mailing list