Title: [158283] trunk/Tools
Revision
158283
Author
[email protected]
Date
2013-10-30 10:53:56 -0700 (Wed, 30 Oct 2013)

Log Message

Teach the style checker how to handle Objective-C categories and NS_ENUM
https://bugs.webkit.org/show_bug.cgi?id=123482

Reviewed by Dan Bernstein.

* Scripts/webkitpy/style/checkers/cpp.py:
(check_spacing_for_function_call): Allow a space before '(' in a line
starting with @interface or @implementation, since this is defining an
Objective-C category rather than a function.
(check_braces): The opening brace of an NS_ENUM should not be on its
own line.
* Scripts/webkitpy/style/checkers/cpp_unittest.py: Added unit tests.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (158282 => 158283)


--- trunk/Tools/ChangeLog	2013-10-30 17:49:55 UTC (rev 158282)
+++ trunk/Tools/ChangeLog	2013-10-30 17:53:56 UTC (rev 158283)
@@ -1,3 +1,18 @@
+2013-10-29  Andy Estes  <[email protected]>
+
+        Teach the style checker how to handle Objective-C categories and NS_ENUM
+        https://bugs.webkit.org/show_bug.cgi?id=123482
+
+        Reviewed by Dan Bernstein.
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (check_spacing_for_function_call): Allow a space before '(' in a line
+        starting with @interface or @implementation, since this is defining an
+        Objective-C category rather than a function.
+        (check_braces): The opening brace of an NS_ENUM should not be on its
+        own line.
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py: Added unit tests.
+
 2013-10-30  Robert Plociennik  <[email protected]>
 
         [EFL] accessibility/textarea-selected-text-range.html is failing

Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py (158282 => 158283)


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2013-10-30 17:49:55 UTC (rev 158282)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2013-10-30 17:53:56 UTC (rev 158283)
@@ -1422,7 +1422,7 @@
             error(line_number, 'whitespace/parens', 2,
                   'Extra space after (')
         if (search(r'\w\s+\(', function_call)
-            and not match(r'\s*(#|typedef|@property)', function_call)):
+            and not match(r'\s*(#|typedef|@property|@interface|@implementation)', function_call)):
             error(line_number, 'whitespace/parens', 4,
                   'Extra space before ( in function call')
         # If the ) is followed only by a newline or a { + newline, assume it's
@@ -2291,13 +2291,13 @@
         # We also allow '#' for #endif and '=' for array initialization.
         previous_line = get_previous_non_blank_line(clean_lines, line_number)[0]
         if ((not search(r'[;:}{)=]\s*$|\)\s*((const|OVERRIDE)\s*)*\s*$', previous_line)
-             or search(r'\b(if|for|foreach|while|switch|else)\b', previous_line))
+             or search(r'\b(if|for|foreach|while|switch|else|NS_ENUM)\b', previous_line))
             and previous_line.find('#') < 0):
             error(line_number, 'whitespace/braces', 4,
                   'This { should be at the end of the previous line')
     elif (search(r'\)\s*(((const|OVERRIDE)\s*)*\s*)?{\s*$', line)
           and line.count('(') == line.count(')')
-          and not search(r'\b(if|for|foreach|while|switch)\b', line)
+          and not search(r'\b(if|for|foreach|while|switch|NS_ENUM)\b', line)
           and not match(r'\s+[A-Z_][A-Z_0-9]+\b', line)):
         error(line_number, 'whitespace/braces', 4,
               'Place brace on its own line for function definitions.')

Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py (158282 => 158283)


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2013-10-30 17:49:55 UTC (rev 158282)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2013-10-30 17:53:56 UTC (rev 158283)
@@ -1647,6 +1647,10 @@
         self.assert_lint('char (*p)[sizeof(foo)] = &foo', '')
         self.assert_lint('char (&ref)[sizeof(foo)] = &foo', '')
         self.assert_lint('const char32 (*table[])[6];', '')
+        self.assert_lint('@interface Foo (Category)', '')
+        self.assert_lint('@interface Foo ()', '')
+        self.assert_lint('@implementation Foo (Category)', '')
+        self.assert_lint('@implementation Foo ()', '')
 
     def test_spacing_before_braces(self):
         self.assert_lint('if (foo){', 'Missing space before {'
@@ -4197,6 +4201,18 @@
             'case foo: return;\n'
             '}\n',
             'This { should be at the end of the previous line  [whitespace/braces] [4]')
+        self.assert_multi_line_lint(
+            'typedef NS_ENUM(NSInteger, type)\n'
+            '{\n'
+            '    0,\n'
+            '    1\n'
+            '};',
+            'This { should be at the end of the previous line  [whitespace/braces] [4]')
+        self.assert_multi_line_lint(
+            'typedef NS_ENUM(NSInteger, type) {\n'
+            '    0,\n'
+            '    1\n'
+            '};', '')
 
         # 3. One-line control clauses should not use braces unless
         #    comments are included or a single statement spans multiple
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to