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 --- .../test/clang-tidy/google-objc-function-naming.m | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 clang-tools-extra/test/clang-tidy/google-objc-function-naming.m (limited to 'clang-tools-extra/test') diff --git a/clang-tools-extra/test/clang-tidy/google-objc-function-naming.m b/clang-tools-extra/test/clang-tidy/google-objc-function-naming.m new file mode 100644 index 00000000000..8ca90f0f09d --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/google-objc-function-naming.m @@ -0,0 +1,52 @@ +// RUN: %check_clang_tidy %s google-objc-function-naming %t + +typedef _Bool bool; + +static bool ispositive(int a) { return a > 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'ispositive' not using function naming conventions described by Google Objective-C style guide +// CHECK-FIXES: static bool Ispositive(int a) { return a > 0; } + +static bool is_positive(int a) { return a > 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'is_positive' not using function naming conventions described by Google Objective-C style guide +// CHECK-FIXES: static bool IsPositive(int a) { return a > 0; } + +static bool isPositive(int a) { return a > 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'isPositive' not using function naming conventions described by Google Objective-C style guide +// CHECK-FIXES: static bool IsPositive(int a) { return a > 0; } + +static bool Is_Positive(int a) { return a > 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'Is_Positive' not using function naming conventions described by Google Objective-C style guide +// CHECK-FIXES: static bool IsPositive(int a) { return a > 0; } + +static bool IsPositive(int a) { return a > 0; } + +bool ispalindrome(const char *str); +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function name 'ispalindrome' not using function naming conventions described by Google Objective-C style guide + +static const char *md5(const char *str) { return 0; } +// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: function name 'md5' not using function naming conventions described by Google Objective-C style guide +// CHECK-FIXES: static const char *Md5(const char *str) { return 0; } + +static const char *MD5(const char *str) { return 0; } + +static const char *URL(void) { return "https://clang.llvm.org/"; } + +static const char *DEFURL(void) { return "https://clang.llvm.org/"; } + +static const char *DEFFooURL(void) { return "https://clang.llvm.org/"; } + +static const char *StringFromNSString(id str) { return ""; } + +void ABLog_String(const char *str); +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function name 'ABLog_String' not using function naming conventions described by Google Objective-C style guide + +void ABLogString(const char *str); + +bool IsPrime(int a); +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function name 'IsPrime' not using function naming conventions described by Google Objective-C style guide + +const char *ABURL(void) { return "https://clang.llvm.org/"; } + +const char *ABFooURL(void) { return "https://clang.llvm.org/"; } + +int main(int argc, const char **argv) { return 0; } -- cgit v1.2.3