Debian Codegraph @

clang-tools-extra/test/clang-tidy/checkers/google/objc-global-variable-declaration.m

raw
1 // RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
2
3 @class NSString;
4
5 static 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
9 extern 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
12 static 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
16 NSString* 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
20 static 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
24 static 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
28 static 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
32 static 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
36 static 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
40 static 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
44 extern 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
48 static NSString* const kGood = @"hello";
49 static NSString* const XYGood = @"hello";
50 static NSString* const X1Good = @"hello";
51 static NSString* gMyIntGood = 0;
52
53 extern NSString* const GTLServiceErrorDomain;
54
55 enum GTLServiceError {
56 GTLServiceErrorQueryResultMissing = -3000,
57 GTLServiceErrorWaitTimedOut = -3001,
58 };
59
60 @implementation Foo
61 - (void)f {
62 int x = 0;
63 static int bar;
64 static const int baz = 42;
65 }
66 @end