Changeset 204723 in webkit


Ignore:
Timestamp:
Aug 22, 2016 9:40:49 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

check-webkit-style does not work with Lambda functions in C++
https://bugs.webkit.org/show_bug.cgi?id=160910

Patch by Jonathan Bedard <Jonathan Bedard> on 2016-08-22
Reviewed by Darin Adler.

This change eliminates false positives on correctly styled lambda functions and includes a few basic checks on capture list.

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

(regex_for_lambda_functions): Added function which checks if a string is the start of a lambda function.
(check_for_non_standard_constructs): Added lambda function check.
(check_spacing_for_function_call): Added lambda function check.
(check_braces): Added lambda function check.

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

(CppStyleTest.test_lambda_functions): Added test function for lambda function style checks.

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r204701 r204723  
     12016-08-22  Jonathan Bedard  <jbedard@apple.com>
     2
     3        check-webkit-style does not work with Lambda functions in C++
     4        https://bugs.webkit.org/show_bug.cgi?id=160910
     5
     6        Reviewed by Darin Adler.
     7
     8        This change eliminates false positives on correctly styled lambda functions and includes a few basic checks on capture list.
     9
     10        * Scripts/webkitpy/style/checkers/cpp.py:
     11        (regex_for_lambda_functions): Added function which checks if a string is the start of a lambda function.
     12        (check_for_non_standard_constructs): Added lambda function check.
     13        (check_spacing_for_function_call): Added lambda function check.
     14        (check_braces): Added lambda function check.
     15        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
     16        (CppStyleTest.test_lambda_functions): Added test function for lambda function style checks.
     17
    1182016-08-21  Alex Christensen  <achristensen@webkit.org>
    219
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py

    r202362 r204723  
    12821282
    12831283
     1284def regex_for_lambda_functions(line, line_number, error):
     1285    result = search(r'\s\[.*?\]\s', line)
     1286    if result:
     1287        group = result.group()
     1288
     1289        targ_error = None
     1290
     1291        if search(r'(\[\s|\s\]|\s,)', group):
     1292            targ_error = [line_number, 'whitespace/brackets', 4,
     1293              'Extra space in capture list.']
     1294
     1295        if targ_error and regex_for_lambda_functions.__last_error != targ_error:
     1296            error(targ_error[0], targ_error[1], targ_error[2], targ_error[3])
     1297        regex_for_lambda_functions.__last_error = targ_error
     1298        return True
     1299    return False
     1300
     1301regex_for_lambda_functions.__last_error = None
     1302
     1303
    12841304def check_for_non_standard_constructs(clean_lines, line_number,
    12851305                                      class_state, error):
     
    14701490    if (  # Ignore control structures.
    14711491        not search(r'\b(if|for|while|switch|return|new|delete)\b', function_call)
     1492        # Ignore lambda functions
     1493        and not regex_for_lambda_functions(function_call, line_number, error)
    14721494        # Ignore pointers/references to functions.
    14731495        and not search(r' \([^)]+\)\([^)]*(\)|,$)', function_call)
     
    24322454        previous_line = get_previous_non_blank_line(clean_lines, line_number)[0]
    24332455        if ((not search(r'[;:}{)=]\s*$|\)\s*((const|override|const override)\s*)?(->\s*\S+)?\s*$', previous_line)
    2434              or search(r'\b(if|for|while|switch|else|NS_ENUM)\b', previous_line))
     2456             or search(r'\b(if|for|while|switch|else|NS_ENUM)\b', previous_line)
     2457             or regex_for_lambda_functions(previous_line, line_number, error))
    24352458            and previous_line.find('#') < 0
    24362459            and previous_line.find('- (') != 0
     
    24412464          and line.count('(') == line.count(')')
    24422465          and not search(r'(\s*(if|for|while|switch|NS_ENUM|@synchronized)|} @catch)\b', line)
     2466          and not regex_for_lambda_functions(line, line_number, error)
    24432467          and line.find("](") < 0
    24442468          and not match(r'\s+[A-Z_][A-Z_0-9]+\b', line)):
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py

    r202362 r204723  
    18821882        self.assert_lint('int main(int argc, char* agrv [])', 'Extra space before [.  [whitespace/brackets] [5]')
    18831883        self.assert_lint('    str [strLength] = \'\\0\';', 'Extra space before [.  [whitespace/brackets] [5]')
     1884
     1885    def test_lambda_functions(self):
     1886        self.assert_lint('        [&] (Type argument) {', '')
     1887        self.assert_lint('        [] {', '')
     1888        self.assert_lint('        [ =] (Type argument) {', 'Extra space in capture list.  [whitespace/brackets] [4]')
     1889        self.assert_lint('        [var, var_ref&] {', '')
     1890        self.assert_lint('        [var , var_ref&] {', 'Extra space in capture list.  [whitespace/brackets] [4]')
     1891        self.assert_lint('        [var,var_ref&] {', 'Missing space after ,  [whitespace/comma] [3]')
    18841892
    18851893    def test_spacing_around_else(self):
Note: See TracChangeset for help on using the changeset viewer.