Title: [244688] trunk/Tools
Revision
244688
Author
[email protected]
Date
2019-04-26 09:25:27 -0700 (Fri, 26 Apr 2019)

Log Message

check-webkit-style complains the first block in while loop.
https://bugs.webkit.org/show_bug.cgi?id=197307

The style checker shouldn't complain about an open brace on
its own line if the last non-whitespace character on the previous
non-blank line is another open brace, because it's likely to
indicate the begining of a nested code block.

Reviewed by Alex Christensen.

* Scripts/webkitpy/style/checkers/cpp.py:
(check_braces):
* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(WebKitStyleTest.test_braces):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (244687 => 244688)


--- trunk/Tools/ChangeLog	2019-04-26 16:08:40 UTC (rev 244687)
+++ trunk/Tools/ChangeLog	2019-04-26 16:25:27 UTC (rev 244688)
@@ -1,3 +1,20 @@
+2019-04-26  Yoshiaki Jitsukawa  <[email protected]>
+
+        check-webkit-style complains the first block in while loop.
+        https://bugs.webkit.org/show_bug.cgi?id=197307
+
+        The style checker shouldn't complain about an open brace on
+        its own line if the last non-whitespace character on the previous
+        non-blank line is another open brace, because it's likely to
+        indicate the begining of a nested code block.
+
+        Reviewed by Alex Christensen.
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (check_braces):
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+        (WebKitStyleTest.test_braces):
+
 2019-04-26  Sihui Liu  <[email protected]>
 
         Stop IDB transactions to release locked database files when network process is ready to suspend

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


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2019-04-26 16:08:40 UTC (rev 244687)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2019-04-26 16:25:27 UTC (rev 244688)
@@ -2513,6 +2513,9 @@
         # ')', or ') const' and doesn't begin with 'if|for|while|switch|else'.
         # We also allow '#' for #endif and '=' for array initialization,
         # and '- (' and '+ (' for Objective-C methods.
+        # Also we don't complain if the last non-whitespace character
+        # on the previous non-blank line is '{' because it's likely to
+        # indicate the begining of a nested code block.
         previous_line = get_previous_non_blank_line(clean_lines, line_number)[0]
         if ((not search(r'[;:}{)=]\s*$|\)\s*((const|override|const override|final|const final)\s*)?(->\s*\S+)?\s*$', previous_line)
              or search(r'\b(if|for|while|switch|else|CF_OPTIONS|NS_ENUM|NS_ERROR_ENUM|NS_OPTIONS)\b', previous_line)
@@ -2519,7 +2522,8 @@
              or regex_for_lambdas_and_blocks(previous_line, line_number, file_state, error))
             and previous_line.find('#') < 0
             and previous_line.find('- (') != 0
-            and previous_line.find('+ (') != 0):
+            and previous_line.find('+ (') != 0
+            and not search(r'{\s*$', previous_line)):
             error(line_number, 'whitespace/braces', 4,
                   'This { should be at the end of the previous line')
     elif (search(r'\)\s*(((const|override|final)\s*)*\s*)?{\s*$', line)

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


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2019-04-26 16:08:40 UTC (rev 244687)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2019-04-26 16:25:27 UTC (rev 244688)
@@ -4891,6 +4891,23 @@
             '        reallyLongParam5);\n'
             '    }\n',
             '')
+        # 6. An open brace on its own line for a nested code block should be allowed.
+        self.assert_multi_line_lint(
+            '    if (condition) {\n'
+            '        {\n'
+            '            j = 1;\n'
+            '        }\n'
+            '    }\n',
+            '')
+        self.assert_multi_line_lint(
+            '    if (condition1\n'
+            '        || condition2\n'
+            '        && condition3) {\n'
+            '        {\n'
+            '            j = 1;\n'
+            '        }\n'
+            '    }\n',
+            '')
 
     def test_null_false_zero(self):
         # 1. In C++, the null pointer value should be written as nullptr. In C,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to