67 lines · plain
1// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t2 3@class NSString;4 5static NSString* const myConstString = @"hello";6// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]7// CHECK-FIXES: static NSString* const kMyConstString = @"hello";8 9extern NSString* const GlobalConstant = @"hey";10// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'GlobalConstant' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]11 12static NSString* MyString = @"hi";13// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'MyString' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]14// CHECK-FIXES: static NSString* gMyString = @"hi";15 16NSString* globalString = @"test";17// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: non-const global variable 'globalString' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]18// CHECK-FIXES: NSString* gGlobalString = @"test";19 20static NSString* a = @"too simple";21// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'a' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]22// CHECK-FIXES: static NSString* a = @"too simple";23 24static NSString* noDef;25// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'noDef' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]26// CHECK-FIXES: static NSString* gNoDef;27 28static NSString* const _notAlpha = @"NotBeginWithAlpha";29// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable '_notAlpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]30// CHECK-FIXES: static NSString* const _notAlpha = @"NotBeginWithAlpha";31 32static NSString* const notCap = @"NotBeginWithCap";33// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'notCap' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]34// CHECK-FIXES: static NSString* const kNotCap = @"NotBeginWithCap";35 36static NSString* const k_Alpha = @"SecondNotAlpha";37// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'k_Alpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]38// CHECK-FIXES: static NSString* const k_Alpha = @"SecondNotAlpha";39 40static NSString* const SecondNotCap = @"SecondNotCapOrNumber";41// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'SecondNotCap' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]42// CHECK-FIXES: static NSString* const kSecondNotCap = @"SecondNotCapOrNumber";43 44extern NSString* Y2Bad;45// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'Y2Bad' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]46// CHECK-FIXES: extern NSString* gY2Bad;47 48static NSString* const kGood = @"hello";49static NSString* const XYGood = @"hello";50static NSString* const X1Good = @"hello";51static NSString* gMyIntGood = 0;52 53extern NSString* const GTLServiceErrorDomain;54 55enum GTLServiceError {56 GTLServiceErrorQueryResultMissing = -3000,57 GTLServiceErrorWaitTimedOut = -3001,58};59 60@implementation Foo61- (void)f {62 int x = 0;63 static int bar;64 static const int baz = 42;65}66@end67