[PATCH] D59283: Fixed global constant/variable naming check on C++ class for ObjC++ files.
This revision was automatically updated to reflect the committed changes. Closed by commit rL356220: Fixed global constant/variable naming check on C++ class for ObjC++ files. (authored by Wizard, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits. Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59283/new/ https://reviews.llvm.org/D59283 Files: clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm Index: clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm === --- clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm +++ clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm @@ -0,0 +1,10 @@ +// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t + +@class NSString; +static NSString* const myConstString = @"hello"; +// 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] +// CHECK-FIXES: static NSString* const kMyConstString = @"hello"; + +class MyTest { +static int not_objc_style; +}; Index: clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp === --- clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp @@ -79,12 +79,16 @@ void GlobalVariableDeclarationCheck::check( const MatchFinder::MatchResult ) { if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "non-const global variable '%0' must have a name which starts with " "'g[A-Z]'") << Decl->getName() << generateFixItHint(Decl, false); } if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "const global variable '%0' must have a name which starts with " "an appropriate prefix") Index: clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm === --- clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm +++ clang-tools-extra/trunk/test/clang-tidy/google-objc-global-variable-declaration.mm @@ -0,0 +1,10 @@ +// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t + +@class NSString; +static NSString* const myConstString = @"hello"; +// 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] +// CHECK-FIXES: static NSString* const kMyConstString = @"hello"; + +class MyTest { +static int not_objc_style; +}; Index: clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp === --- clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/google/GlobalVariableDeclarationCheck.cpp @@ -79,12 +79,16 @@ void GlobalVariableDeclarationCheck::check( const MatchFinder::MatchResult ) { if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "non-const global variable '%0' must have a name which starts with " "'g[A-Z]'") << Decl->getName() << generateFixItHint(Decl, false); } if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "const global variable '%0' must have a name which starts with " "an appropriate prefix") ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59283: Fixed global constant/variable naming check on C++ class for ObjC++ files.
Wizard updated this revision to Diff 190750. Wizard added a comment. add new line Repository: rCTE Clang Tools Extra CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59283/new/ https://reviews.llvm.org/D59283 Files: clang-tidy/google/GlobalVariableDeclarationCheck.cpp test/clang-tidy/google-objc-global-variable-declaration.mm Index: test/clang-tidy/google-objc-global-variable-declaration.mm === --- /dev/null +++ test/clang-tidy/google-objc-global-variable-declaration.mm @@ -0,0 +1,10 @@ +// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t + +@class NSString; +static NSString* const myConstString = @"hello"; +// 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] +// CHECK-FIXES: static NSString* const kMyConstString = @"hello"; + +class MyTest { +static int not_objc_style; +}; Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp === --- clang-tidy/google/GlobalVariableDeclarationCheck.cpp +++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp @@ -79,12 +79,16 @@ void GlobalVariableDeclarationCheck::check( const MatchFinder::MatchResult ) { if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "non-const global variable '%0' must have a name which starts with " "'g[A-Z]'") << Decl->getName() << generateFixItHint(Decl, false); } if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "const global variable '%0' must have a name which starts with " "an appropriate prefix") Index: test/clang-tidy/google-objc-global-variable-declaration.mm === --- /dev/null +++ test/clang-tidy/google-objc-global-variable-declaration.mm @@ -0,0 +1,10 @@ +// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t + +@class NSString; +static NSString* const myConstString = @"hello"; +// 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] +// CHECK-FIXES: static NSString* const kMyConstString = @"hello"; + +class MyTest { +static int not_objc_style; +}; Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp === --- clang-tidy/google/GlobalVariableDeclarationCheck.cpp +++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp @@ -79,12 +79,16 @@ void GlobalVariableDeclarationCheck::check( const MatchFinder::MatchResult ) { if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "non-const global variable '%0' must have a name which starts with " "'g[A-Z]'") << Decl->getName() << generateFixItHint(Decl, false); } if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "const global variable '%0' must have a name which starts with " "an appropriate prefix") ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59283: Fixed global constant/variable naming check on C++ class for ObjC++ files.
hokein accepted this revision. hokein added inline comments. This revision is now accepted and ready to land. Comment at: test/clang-tidy/google-objc-global-variable-declaration.mm:11 +}; \ No newline at end of file nit: I think we should have a newline at end of file. Repository: rCTE Clang Tools Extra CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59283/new/ https://reviews.llvm.org/D59283 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59283: Fixed global constant/variable naming check on C++ class for ObjC++ files.
Wizard updated this revision to Diff 190462. Wizard added a comment. fix ObjC++ test Repository: rCTE Clang Tools Extra CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59283/new/ https://reviews.llvm.org/D59283 Files: clang-tidy/google/GlobalVariableDeclarationCheck.cpp test/clang-tidy/google-objc-global-variable-declaration.mm Index: test/clang-tidy/google-objc-global-variable-declaration.mm === --- /dev/null +++ test/clang-tidy/google-objc-global-variable-declaration.mm @@ -0,0 +1,10 @@ +// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t + +@class NSString; +static NSString* const myConstString = @"hello"; +// 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] +// CHECK-FIXES: static NSString* const kMyConstString = @"hello"; + +class MyTest { +static int not_objc_style; +}; \ No newline at end of file Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp === --- clang-tidy/google/GlobalVariableDeclarationCheck.cpp +++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp @@ -79,12 +79,16 @@ void GlobalVariableDeclarationCheck::check( const MatchFinder::MatchResult ) { if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "non-const global variable '%0' must have a name which starts with " "'g[A-Z]'") << Decl->getName() << generateFixItHint(Decl, false); } if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "const global variable '%0' must have a name which starts with " "an appropriate prefix") Index: test/clang-tidy/google-objc-global-variable-declaration.mm === --- /dev/null +++ test/clang-tidy/google-objc-global-variable-declaration.mm @@ -0,0 +1,10 @@ +// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t + +@class NSString; +static NSString* const myConstString = @"hello"; +// 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] +// CHECK-FIXES: static NSString* const kMyConstString = @"hello"; + +class MyTest { +static int not_objc_style; +}; \ No newline at end of file Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp === --- clang-tidy/google/GlobalVariableDeclarationCheck.cpp +++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp @@ -79,12 +79,16 @@ void GlobalVariableDeclarationCheck::check( const MatchFinder::MatchResult ) { if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "non-const global variable '%0' must have a name which starts with " "'g[A-Z]'") << Decl->getName() << generateFixItHint(Decl, false); } if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "const global variable '%0' must have a name which starts with " "an appropriate prefix") ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59283: Fixed global constant/variable naming check on C++ class for ObjC++ files.
Wizard updated this revision to Diff 190461. Wizard added a comment. Resolve comments Repository: rCTE Clang Tools Extra CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59283/new/ https://reviews.llvm.org/D59283 Files: clang-tidy/google/GlobalVariableDeclarationCheck.cpp test/clang-tidy/google-objc-global-variable-declaration.mm Index: test/clang-tidy/google-objc-global-variable-declaration.mm === --- /dev/null +++ test/clang-tidy/google-objc-global-variable-declaration.mm @@ -0,0 +1,5 @@ +// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t + +class MyTest { +static int not_objc_style; +}; \ No newline at end of file Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp === --- clang-tidy/google/GlobalVariableDeclarationCheck.cpp +++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp @@ -79,12 +79,16 @@ void GlobalVariableDeclarationCheck::check( const MatchFinder::MatchResult ) { if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "non-const global variable '%0' must have a name which starts with " "'g[A-Z]'") << Decl->getName() << generateFixItHint(Decl, false); } if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "const global variable '%0' must have a name which starts with " "an appropriate prefix") Index: test/clang-tidy/google-objc-global-variable-declaration.mm === --- /dev/null +++ test/clang-tidy/google-objc-global-variable-declaration.mm @@ -0,0 +1,5 @@ +// RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t + +class MyTest { +static int not_objc_style; +}; \ No newline at end of file Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp === --- clang-tidy/google/GlobalVariableDeclarationCheck.cpp +++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp @@ -79,12 +79,16 @@ void GlobalVariableDeclarationCheck::check( const MatchFinder::MatchResult ) { if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "non-const global variable '%0' must have a name which starts with " "'g[A-Z]'") << Decl->getName() << generateFixItHint(Decl, false); } if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) { +if (Decl->isStaticDataMember()) + return; diag(Decl->getLocation(), "const global variable '%0' must have a name which starts with " "an appropriate prefix") ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59283: Fixed global constant/variable naming check on C++ class for ObjC++ files.
hokein added inline comments. Comment at: clang-tidy/google/GlobalVariableDeclarationCheck.cpp:82 if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) { +if (Decl->isStaticDataMember()) { + return; nit: removing the `{}`, the same below. Comment at: test/clang-tidy/google-objc-global-variable-declaration.mm:38 +class MyTest { +static int not_objc_style; instead of moving `.m` to `.mm`, I think we can create a new ".mm" file for testing this case. Repository: rCTE Clang Tools Extra CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59283/new/ https://reviews.llvm.org/D59283 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59283: Fixed global constant/variable naming check on C++ class for ObjC++ files.
Wizard created this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D59283 Files: clang-tidy/google/GlobalVariableDeclarationCheck.cpp test/clang-tidy/google-objc-global-variable-declaration.m test/clang-tidy/google-objc-global-variable-declaration.mm Index: test/clang-tidy/google-objc-global-variable-declaration.mm === --- test/clang-tidy/google-objc-global-variable-declaration.mm +++ test/clang-tidy/google-objc-global-variable-declaration.mm @@ -35,6 +35,10 @@ extern NSString* const GTLServiceErrorDomain; +class MyTest { +static int not_objc_style; +}; + enum GTLServiceError { GTLServiceErrorQueryResultMissing = -3000, GTLServiceErrorWaitTimedOut = -3001, Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp === --- clang-tidy/google/GlobalVariableDeclarationCheck.cpp +++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp @@ -79,12 +79,18 @@ void GlobalVariableDeclarationCheck::check( const MatchFinder::MatchResult ) { if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) { +if (Decl->isStaticDataMember()) { + return; +} diag(Decl->getLocation(), "non-const global variable '%0' must have a name which starts with " "'g[A-Z]'") << Decl->getName() << generateFixItHint(Decl, false); } if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) { +if (Decl->isStaticDataMember()) { + return; +} diag(Decl->getLocation(), "const global variable '%0' must have a name which starts with " "an appropriate prefix") Index: test/clang-tidy/google-objc-global-variable-declaration.mm === --- test/clang-tidy/google-objc-global-variable-declaration.mm +++ test/clang-tidy/google-objc-global-variable-declaration.mm @@ -35,6 +35,10 @@ extern NSString* const GTLServiceErrorDomain; +class MyTest { +static int not_objc_style; +}; + enum GTLServiceError { GTLServiceErrorQueryResultMissing = -3000, GTLServiceErrorWaitTimedOut = -3001, Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp === --- clang-tidy/google/GlobalVariableDeclarationCheck.cpp +++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp @@ -79,12 +79,18 @@ void GlobalVariableDeclarationCheck::check( const MatchFinder::MatchResult ) { if (const auto *Decl = Result.Nodes.getNodeAs("global_var")) { +if (Decl->isStaticDataMember()) { + return; +} diag(Decl->getLocation(), "non-const global variable '%0' must have a name which starts with " "'g[A-Z]'") << Decl->getName() << generateFixItHint(Decl, false); } if (const auto *Decl = Result.Nodes.getNodeAs("global_const")) { +if (Decl->isStaticDataMember()) { + return; +} diag(Decl->getLocation(), "const global variable '%0' must have a name which starts with " "an appropriate prefix") ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits