From e34a761d5b2b71a4a79a5ce05ce2af5f11a16a64 Mon Sep 17 00:00:00 2001 From: Stephane Moore Date: Sat, 17 Nov 2018 02:37:21 +0000 Subject: [clang-tidy/checks] Implement a clang-tidy check to verify Google Objective-C function naming conventions 📜 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: §1 Description This check finds function names in function declarations in Objective-C files that do not follow the naming pattern described in the Google Objective-C Style Guide. Function names should be in UpperCamelCase and functions that are not of static storage class should have an appropriate prefix as described in the Google Objective-C Style Guide. The function `main` is a notable exception. Function declarations in expansions in system headers are ignored. Example conforming function definitions: ``` static bool IsPositive(int i) { return i > 0; } static bool ABIsPositive(int i) { return i > 0; } bool ABIsNegative(int i) { return i < 0; } ``` A fixit hint is generated for functions of static storage class but otherwise the check does not generate a fixit hint because an appropriate prefix for the function cannot be determined. §2 Test Notes * Verified clang-tidy tests pass successfully. * Used check_clang_tidy.py to verify expected output of processing google-objc-function-naming.m Reviewers: benhamilton, hokein, Wizard, aaron.ballman Reviewed By: benhamilton Subscribers: Eugene.Zelenko, mgorny, xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D51575 llvm-svn: 347132 --- .../clang-tidy/google/FunctionNamingCheck.h | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/google/FunctionNamingCheck.h (limited to 'clang-tools-extra/clang-tidy/google/FunctionNamingCheck.h') diff --git a/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.h b/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.h new file mode 100644 index 00000000000..46499e90ac2 --- /dev/null +++ b/clang-tools-extra/clang-tidy/google/FunctionNamingCheck.h @@ -0,0 +1,43 @@ +//===--- FunctionNamingCheck.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_FUNCTION_NAMING_CHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_OBJC_FUNCTION_NAMING_CHECK_H + +#include "../ClangTidy.h" +#include "llvm/ADT/StringRef.h" + +namespace clang { +namespace tidy { +namespace google { +namespace objc { + +/// Finds function names that do not conform to the recommendations of the +/// Google Objective-C Style Guide. Function names should be in upper camel case +/// including capitalized acronyms and initialisms. Functions that are not of +/// static storage class must also have an appropriate prefix. The function +/// `main` is an exception. Note that this check does not apply to Objective-C +/// method or property declarations. +/// +/// For the user-facing documentation see: +/// http://clang.llvm.org/extra/clang-tidy/checks/google-objc-function-naming.html +class FunctionNamingCheck : public ClangTidyCheck { +public: + FunctionNamingCheck(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_FUNCTION_NAMING_CHECK_H -- cgit v1.2.3