Changeset 156105 in webkit


Ignore:
Timestamp:
Sep 19, 2013, 11:13:19 AM (12 years ago)
Author:
mitz@apple.com
Message:

Add a style guideline regarding spacing in range-based for loops
https://bugs.webkit.org/show_bug.cgi?id=121620

Reviewed by Anders Carlsson.

Tools:

  • Scripts/webkitpy/style/checkers/cpp.py:

(check_spacing): Added checking that there are spaces around the colon in a range-based for
loop.
(CppChecker): Added whitespace/colon to the categories set.

  • Scripts/webkitpy/style/checkers/cpp_unittest.py:

(WebKitStyleTest.test_spacing): Added two tests for the new check.

Websites/webkit.org:

  • coding/coding-style.html: Added the guideline that spaces should be placed

around the colon in a range-based for loop.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r156100 r156105  
     12013-09-19  Dan Bernstein  <mitz@apple.com>
     2
     3        Add a style guideline regarding spacing in range-based for loops
     4        https://bugs.webkit.org/show_bug.cgi?id=121620
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * Scripts/webkitpy/style/checkers/cpp.py:
     9        (check_spacing): Added checking that there are spaces around the colon in a range-based for
     10        loop.
     11        (CppChecker): Added whitespace/colon to the categories set.
     12        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
     13        (WebKitStyleTest.test_spacing): Added two tests for the new check.
     14
    1152013-09-18  Sam Weinig  <sam@webkit.org>
    216
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py

    r155535 r156105  
    19081908        condition, rest = up_to_unmatched_closing_paren(matched.group('remainder'))
    19091909        if condition is not None:
     1910            if statement == 'for' and search(r'(?:[^ :]:[^:]|[^:]:[^ :])', condition):
     1911                error(line_number, 'whitespace/colon', 4, 'Missing space around : in range-based for statement')
    19101912            condition_match = search(r'(?P<leading>[ ]*)(?P<separator>.).*[^ ]+(?P<trailing>[ ]*)', condition)
    19111913            if condition_match:
     
    37003702        'whitespace/blank_line',
    37013703        'whitespace/braces',
     3704        'whitespace/colon',
    37023705        'whitespace/comma',
    37033706        'whitespace/comments',
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py

    r155535 r156105  
    38503850        #     '')
    38513851
    3852         # 3. Place spaces between control statements and their parentheses.
     3852        # 3. Place spaces around the colon in a range-based for loop.
     3853        self.assert_multi_line_lint(
     3854            '    for (const WTF::Vector& vector : vectors)\n'
     3855            '        process(vector);\n',
     3856            '')
     3857
     3858        self.assert_multi_line_lint(
     3859            '    for (const Vector& vector: vectors)\n'
     3860            '        process(vector);\n',
     3861            'Missing space around : in range-based for statement  [whitespace/colon] [4]')
     3862
     3863        # 5. Place spaces between control statements and their parentheses.
    38533864        self.assert_multi_line_lint(
    38543865            '    if (condition)\n'
     
    38603871            'Missing space before ( in if(  [whitespace/parens] [5]')
    38613872
    3862         # 4. Do not place spaces between a function and its parentheses,
     3873        # 6. Do not place spaces between a function and its parentheses,
    38633874        #    or between a parenthesis and its content.
    38643875        self.assert_multi_line_lint(
  • trunk/Websites/webkit.org/ChangeLog

    r155488 r156105  
     12013-09-19  Dan Bernstein  <mitz@apple.com>
     2
     3        Add a style guideline regarding spacing in range-based for loops
     4        https://bugs.webkit.org/show_bug.cgi?id=121620
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * coding/coding-style.html: Added the guideline that spaces should be placed
     9        around the colon in a range-based for loop.
     10
    1112013-09-10  Beth Dakin  <bdakin@apple.com>
    212
  • trunk/Websites/webkit.org/coding/coding-style.html

    r138068 r156105  
    186186c = a|b;
    187187return condition ? 1:0;
     188</pre>
     189</li>
     190
     191<li id="spacing-for-colon">Place spaces around the colon in a range-based for loop.
     192<h4 class="right">Right:</h4>
     193<pre class="code">
     194Vector&lt;PluginModuleInfo> plugins;
     195for (const auto&amp; plugin : plugins)
     196    registerPlugin(plugin);
     197</pre>
     198
     199<h4 class="wrong">Wrong:</h4>
     200<pre class="code">
     201Vector&lt;PluginModuleInfo> plugins;
     202for (const auto&amp; plugin: plugins)
     203    registerPlugin(plugin);
    188204</pre>
    189205</li>
Note: See TracChangeset for help on using the changeset viewer.