Modified: trunk/Tools/ChangeLog (204722 => 204723)
--- trunk/Tools/ChangeLog 2016-08-22 16:19:20 UTC (rev 204722)
+++ trunk/Tools/ChangeLog 2016-08-22 16:40:49 UTC (rev 204723)
@@ -1,3 +1,20 @@
+2016-08-22 Jonathan Bedard <jbed...@apple.com>
+
+ check-webkit-style does not work with Lambda functions in C++
+ https://bugs.webkit.org/show_bug.cgi?id=160910
+
+ 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.
+
2016-08-21 Alex Christensen <achristen...@webkit.org>
URLParser should parse IPv4 addresses
Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py (204722 => 204723)
--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py 2016-08-22 16:19:20 UTC (rev 204722)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py 2016-08-22 16:40:49 UTC (rev 204723)
@@ -1281,6 +1281,26 @@
return True
+def regex_for_lambda_functions(line, line_number, error):
+ result = search(r'\s\[.*?\]\s', line)
+ if result:
+ group = result.group()
+
+ targ_error = None
+
+ if search(r'(\[\s|\s\]|\s,)', group):
+ targ_error = [line_number, 'whitespace/brackets', 4,
+ 'Extra space in capture list.']
+
+ if targ_error and regex_for_lambda_functions.__last_error != targ_error:
+ error(targ_error[0], targ_error[1], targ_error[2], targ_error[3])
+ regex_for_lambda_functions.__last_error = targ_error
+ return True
+ return False
+
+regex_for_lambda_functions.__last_error = None
+
+
def check_for_non_standard_constructs(clean_lines, line_number,
class_state, error):
"""Logs an error if we see certain non-ANSI constructs ignored by gcc-2.
@@ -1469,6 +1489,8 @@
# they'll never need to wrap.
if ( # Ignore control structures.
not search(r'\b(if|for|while|switch|return|new|delete)\b', function_call)
+ # Ignore lambda functions
+ and not regex_for_lambda_functions(function_call, line_number, error)
# Ignore pointers/references to functions.
and not search(r' \([^)]+\)\([^)]*(\)|,$)', function_call)
# Ignore pointers/references to arrays.
@@ -2431,7 +2453,8 @@
# and '- (' and '+ (' for Objective-C methods.
previous_line = get_previous_non_blank_line(clean_lines, line_number)[0]
if ((not search(r'[;:}{)=]\s*$|\)\s*((const|override|const override)\s*)?(->\s*\S+)?\s*$', previous_line)
- or search(r'\b(if|for|while|switch|else|NS_ENUM)\b', previous_line))
+ or search(r'\b(if|for|while|switch|else|NS_ENUM)\b', previous_line)
+ or regex_for_lambda_functions(previous_line, line_number, error))
and previous_line.find('#') < 0
and previous_line.find('- (') != 0
and previous_line.find('+ (') != 0):
@@ -2440,6 +2463,7 @@
elif (search(r'\)\s*(((const|override)\s*)*\s*)?{\s*$', line)
and line.count('(') == line.count(')')
and not search(r'(\s*(if|for|while|switch|NS_ENUM|@synchronized)|} @catch)\b', line)
+ and not regex_for_lambda_functions(line, line_number, error)
and line.find("](") < 0
and not match(r'\s+[A-Z_][A-Z_0-9]+\b', line)):
error(line_number, 'whitespace/braces', 4,
Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py (204722 => 204723)
--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py 2016-08-22 16:19:20 UTC (rev 204722)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py 2016-08-22 16:40:49 UTC (rev 204723)
@@ -1882,6 +1882,14 @@
self.assert_lint('int main(int argc, char* agrv [])', 'Extra space before [. [whitespace/brackets] [5]')
self.assert_lint(' str [strLength] = \'\\0\';', 'Extra space before [. [whitespace/brackets] [5]')
+ def test_lambda_functions(self):
+ self.assert_lint(' [&] (Type argument) {', '')
+ self.assert_lint(' [] {', '')
+ self.assert_lint(' [ =] (Type argument) {', 'Extra space in capture list. [whitespace/brackets] [4]')
+ self.assert_lint(' [var, var_ref&] {', '')
+ self.assert_lint(' [var , var_ref&] {', 'Extra space in capture list. [whitespace/brackets] [4]')
+ self.assert_lint(' [var,var_ref&] {', 'Missing space after , [whitespace/comma] [3]')
+
def test_spacing_around_else(self):
self.assert_lint('}else {', 'Missing space before else'
' [whitespace/braces] [5]')