Skip to content

Commit

Permalink
[clang-tidy] add new check to find out objc ivars which do not have p…
Browse files Browse the repository at this point in the history
…refix '_'

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

llvm-svn: 330492
  • Loading branch information
ynzhang0509 committed Apr 20, 2018
1 parent c8ac0a6 commit e3f50ec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Expand Up @@ -109,6 +109,7 @@ namespace readability {
m(TemplateParameter) \
m(TypeAlias) \
m(MacroDefinition) \
m(ObjcIvar) \

enum StyleKind {
#define ENUMERATE(v) SK_ ## v,
Expand Down Expand Up @@ -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;

Expand Down
@@ -0,0 +1,15 @@
// RUN: %check_clang_tidy %s readability-identifier-naming %t \
// RUN: -config='{CheckOptions: \
// RUN: [{key: readability-identifier-naming.ObjcIvarPrefix, value: '_'}]}' \
// RUN: --

@interface Foo
@end

@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;
}
@end

0 comments on commit e3f50ec

Please sign in to comment.