summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.h
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2017-11-07 08:53:37 +0000
committerHaojian Wu <hokein@google.com>2017-11-07 08:53:37 +0000
commit5529a244e1fee8dbefa239b93282a71eb4ef82bf (patch)
treedf2e1a8a1e8541133ed19bad85a78151331eeda4 /clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.h
parentc02b237e467c825d23cda36e178abf769629c9d0 (diff)
downloadbcm5719-llvm-5529a244e1fee8dbefa239b93282a71eb4ef82bf.tar.gz
bcm5719-llvm-5529a244e1fee8dbefa239b93282a71eb4ef82bf.zip
Add new check in google module for Objective-C code to ensure global variables follow the naming convention of Google Objective-C Style Guide
Summary: This is a new checker for objc files in clang-tidy. The new check finds global variable declarations in Objective-C files that are not follow the pattern of variable names in Google's Objective-C Style Guide. All the global variables should follow the pattern of "g[A-Z].*" (variables) or "k[A-Z].*" (constants). The check will suggest a variable name that follows the pattern if it can be inferred from the original name. Patch by Yan Zhang! Reviewers: benhamilton, hokein, alexfh Reviewed By: hokein Subscribers: Eugene.Zelenko, mgorny Differential Revision: https://reviews.llvm.org/D39391 llvm-svn: 317552
Diffstat (limited to 'clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.h')
-rw-r--r--clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.h b/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.h
new file mode 100644
index 00000000000..ed0352bb871
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.h
@@ -0,0 +1,39 @@
+//===--- GlobalVariableDeclarationCheck.h - clang-tidy-----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_GLOBAL_VARIABLE_DECLARATION_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_GLOBAL_VARIABLE_DECLARATION_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace google {
+namespace objc {
+
+/// The check for Objective-C global variables and constants naming convention.
+/// The declaration should follow the patterns of 'k[A-Z].*' (constants) or
+/// 'g[A-Z].*' (variables).
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/google-objc-global-variable-declaration.html
+class GlobalVariableDeclarationCheck : public ClangTidyCheck {
+ public:
+ GlobalVariableDeclarationCheck(StringRef Name, ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace objc
+} // namespace google
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_GLOBAL_VARIABLE_DECLARATION_H
OpenPOWER on IntegriCloud