Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py (283624 => 283625)
--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py 2021-10-06 15:56:21 UTC (rev 283624)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py 2021-10-06 15:57:51 UTC (rev 283625)
@@ -2334,12 +2334,26 @@
error(line_number, 'whitespace/brackets', 5,
'Extra space before [.')
- # There should always be a single space in between braces on the same line.
- if search(r'\{\}', line):
- error(line_number, 'whitespace/braces', 5, 'Missing space inside { }.')
- if search(r'\{\s\s+\}', line):
- error(line_number, 'whitespace/braces', 5, 'Too many spaces inside { }.')
+ # Try to avoid false positives when braces are inside of a string
+ if not search(r'"[^"]*\{.*\}[^"]*"', line):
+ # There should always be a single space in between braces on the same
+ # line.
+ if search(r'\{\}', line):
+ error(line_number, 'whitespace/braces', 5, 'Missing space inside { }.')
+ if search(r'\{\s\s+\}', line):
+ error(line_number, 'whitespace/braces', 5, 'Too many spaces inside { }.')
+ # Also a single space inside of braces with an initializer value inside
+ # of them.
+ if search(r'\{[^\s\}]', line):
+ error(line_number, 'whitespace/braces', 5, 'Missing space after {.')
+ if search(r'[^\s\{]\}', line):
+ error(line_number, 'whitespace/braces', 5, 'Missing space before }.')
+ if search(r'\{\s\s+[^\s\}]', line):
+ error(line_number, 'whitespace/braces', 5, 'Too many spaces after {.')
+ if search(r'[^\s\{]\s\+\}', line):
+ error(line_number, 'whitespace/braces', 5, 'Too many spaces before }.')
+
# You shouldn't have a space before a semicolon at the end of the line.
# There's a special case for "for" since the style guide allows space before
# the semicolon there.
Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py (283624 => 283625)
--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py 2021-10-06 15:56:21 UTC (rev 283624)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py 2021-10-06 15:57:51 UTC (rev 283625)
@@ -1844,7 +1844,7 @@
self.assert_lint(
'''\
const int foo[] =
- {1, 2, 3 };''',
+ { 1, 2, 3 };''',
'')
# For single line, unmatched '}' with a ';' is ignored (not enough context)
self.assert_multi_line_lint(
@@ -2150,6 +2150,24 @@
self.assert_lint(' { }', '')
self.assert_lint(' {}', 'Missing space inside { }. [whitespace/braces] [5]')
self.assert_lint(' { }', 'Too many spaces inside { }. [whitespace/braces] [5]')
+ self.assert_lint(' }', '') # closing brace by itself is fine
+ self.assert_lint(' int64_t {0xffffffff }', 'Missing space after {. [whitespace/braces] [5]')
+ self.assert_lint(' int64_t { 0xffffffff}', 'Missing space before }. [whitespace/braces] [5]')
+ self.assert_lint(' int64_t { 0xffffffff }', '')
+ self.assert_lint(' IntTuple {1, 2 }', 'Missing space after {. [whitespace/braces] [5]')
+ self.assert_lint(' IntTuple { 1, 2}', 'Missing space before }. [whitespace/braces] [5]')
+ self.assert_lint(' IntTuple { 1, 2 }', '')
+ self.assert_lint(' int a[2][2] = {{ 1, 2 }, { 3, 4 } };', 'Missing space after {. [whitespace/braces] [5]')
+ self.assert_lint(' int a[2][2] = { {1, 2 }, { 3, 4 } };', 'Missing space after {. [whitespace/braces] [5]')
+ self.assert_lint(' int a[2][2] = { { 1, 2 }, {3, 4 } };', 'Missing space after {. [whitespace/braces] [5]')
+ self.assert_lint(' int a[2][2] = { { 1, 2}, { 3, 4 } };', 'Missing space before }. [whitespace/braces] [5]')
+ self.assert_lint(' int a[2][2] = { { 1, 2 }, { 3, 4} };', 'Missing space before }. [whitespace/braces] [5]')
+ self.assert_lint(' int a[2][2] = { { 1, 2 }, { 3, 4 }};', 'Missing space before }. [whitespace/braces] [5]')
+ self.assert_lint(' int a[2][2] = { { 1, 2 }, { 3, 4 } };', '')
+ self.assert_lint(' StrPair {"strings", "inside" }', 'Missing space after {. [whitespace/braces] [5]')
+ self.assert_lint(' StrPair { "strings", "inside"}', 'Missing space before }. [whitespace/braces] [5]')
+ self.assert_lint(' StrPair { "strings", "inside" }', '')
+ self.assert_lint(' foo("{braces in a string}");', '')
def test_spacing_before_brackets(self):
self.assert_lint('delete [] base;', '')
@@ -4058,7 +4076,7 @@
FOO_TWO
};
enum { FOO_ONE };
- enum {FooOne, fooTwo};
+ enum { FooOne, fooTwo };
enum {
FOO_ONE
};''',
@@ -4110,7 +4128,7 @@
FOO_TWO
};
enum class Foo { FOO_ONE };
- enum class Foo {FooOne, fooTwo};
+ enum class Foo { FooOne, fooTwo };
enum class Foo {
FOO_ONE
};''',
@@ -4486,7 +4504,7 @@
'namespace WebCore {\n'
'#define abc(x) x; \\\n'
' x\n'
- ' void* x;'
+ ' void* x;\n'
'}',
'Code inside a namespace should not be indented. [whitespace/indent] [4]',
'foo.cpp')