- Revision
- 158342
- Author
- [email protected]
- Date
- 2013-10-30 21:11:02 -0700 (Wed, 30 Oct 2013)
Log Message
Teach the style checker about ENUM_CLASS
https://bugs.webkit.org/show_bug.cgi?id=123528
Reviewed by Andy Estes.
* Scripts/webkitpy/style/checkers/cpp.py:
(_EnumState.process_clean_line): Make content of an ENUM_CLASS declaration
equivalent to enum content for checking.
(check_braces): Allow semicolon at the end.
* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(NoNonVirtualDestructorsTest.test_enum_casing):
(NoNonVirtualDestructorsTest.test_enum_trailing_semicolon):
(WebKitStyleTest.test_braces):
Test it.
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (158341 => 158342)
--- trunk/Tools/ChangeLog 2013-10-31 03:52:23 UTC (rev 158341)
+++ trunk/Tools/ChangeLog 2013-10-31 04:11:02 UTC (rev 158342)
@@ -1,3 +1,21 @@
+2013-10-30 Alexey Proskuryakov <[email protected]>
+
+ Teach the style checker about ENUM_CLASS
+ https://bugs.webkit.org/show_bug.cgi?id=123528
+
+ Reviewed by Andy Estes.
+
+ * Scripts/webkitpy/style/checkers/cpp.py:
+ (_EnumState.process_clean_line): Make content of an ENUM_CLASS declaration
+ equivalent to enum content for checking.
+ (check_braces): Allow semicolon at the end.
+
+ * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+ (NoNonVirtualDestructorsTest.test_enum_casing):
+ (NoNonVirtualDestructorsTest.test_enum_trailing_semicolon):
+ (WebKitStyleTest.test_braces):
+ Test it.
+
2013-10-30 Ryosuke Niwa <[email protected]>
kill-old-processes should kill Web Socket script
Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py (158341 => 158342)
--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py 2013-10-31 03:52:23 UTC (rev 158341)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py 2013-10-31 04:11:02 UTC (rev 158342)
@@ -1193,7 +1193,7 @@
expr_all_uppercase = r'\s*[A-Z0-9_]+\s*(?:=\s*[a-zA-Z0-9]+\s*)?,?\s*$'
expr_starts_lowercase = r'\s*[a-z]'
expr_enum_end = r'}\s*(?:[a-zA-Z0-9]+\s*(?:=\s*[a-zA-Z0-9]+)?)?\s*;\s*'
- expr_enum_start = r'\s*enum(?:\s+[a-zA-Z0-9]+)?\s*\{?\s*'
+ expr_enum_start = r'\s*(?:enum(?:\s+[a-zA-Z0-9]+)?|ENUM_CLASS\s*\([a-zA-Z0-9]+\))\s*\{?\s*'
if self.in_enum_decl:
if match(r'\s*' + expr_enum_end + r'$', line):
self.in_enum_decl = False
@@ -2291,13 +2291,13 @@
# We also allow '#' for #endif and '=' for array initialization.
previous_line = get_previous_non_blank_line(clean_lines, line_number)[0]
if ((not search(r'[;:}{)=]\s*$|\)\s*((const|OVERRIDE)\s*)*\s*$', previous_line)
- or search(r'\b(if|for|foreach|while|switch|else|NS_ENUM)\b', previous_line))
+ or search(r'\b(if|for|foreach|while|switch|else|NS_ENUM|ENUM_CLASS)\b', previous_line))
and previous_line.find('#') < 0):
error(line_number, 'whitespace/braces', 4,
'This { should be at the end of the previous line')
elif (search(r'\)\s*(((const|OVERRIDE)\s*)*\s*)?{\s*$', line)
and line.count('(') == line.count(')')
- and not search(r'\b(if|for|foreach|while|switch|NS_ENUM)\b', line)
+ and not search(r'\b(if|for|foreach|while|switch|NS_ENUM|ENUM_CLASS)\b', line)
and not match(r'\s+[A-Z_][A-Z_0-9]+\b', line)):
error(line_number, 'whitespace/braces', 4,
'Place brace on its own line for function definitions.')
@@ -2341,7 +2341,7 @@
break
if (search(r'{.*}\s*;', line)
and line.count('{') == line.count('}')
- and not search(r'struct|class|enum|\s*=\s*{', line)):
+ and not search(r'struct|class|enum|ENUM_CLASS|\s*=\s*{', line)):
error(line_number, 'readability/braces', 4,
"You don't need a ; after a }")
Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py (158341 => 158342)
--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py 2013-10-31 03:52:23 UTC (rev 158341)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py 2013-10-31 04:11:02 UTC (rev 158342)
@@ -3277,6 +3277,39 @@
self.assert_multi_line_lint(
'''\
+ ENUM_CLASS(Foo) {
+ FOO_ONE = 1,
+ FOO_TWO
+ };
+ ENUM_CLASS(Foo) { FOO_ONE };
+ ENUM_CLASS(Foo) {FooOne, fooTwo};
+ ENUM_CLASS(Foo) {
+ FOO_ONE
+ };''',
+ ['enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4]'] * 5)
+
+ self.assert_multi_line_lint(
+ '''\
+ ENUM_CLASS(Foo) {
+ fooOne = 1,
+ FooTwo = 2
+ };''',
+ 'enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4]')
+
+ self.assert_multi_line_lint(
+ '''\
+ ENUM_CLASS(Foo) {
+ FooOne = 1,
+ FooTwo
+ } fooVar = FooOne;
+ ENUM_CLASS(Enum123) {
+ FooOne,
+ FooTwo = FooOne,
+ };''',
+ '')
+
+ self.assert_multi_line_lint(
+ '''\
// WebIDL enum
enum Foo {
FOO_ONE = 1,
@@ -3290,6 +3323,26 @@
enum Foo { FOO_ONE, FOO_TWO };''',
'')
+ def test_enum_trailing_semicolon(self):
+ self.assert_lint(
+ 'enum MyEnum { Value1, Value2 };',
+ '')
+ self.assert_lint(
+ 'enum MyEnum {\n'
+ ' Value1,\n'
+ ' Value2\n'
+ '};',
+ '')
+ self.assert_lint(
+ 'ENUM_CLASS(CPP11EnumClass) { Value1, Value2 };',
+ '')
+ self.assert_lint(
+ 'ENUM_CLASS(MyEnum) {\n'
+ ' Value1,\n'
+ ' Value2\n'
+ '};',
+ '')
+
def test_destructor_non_virtual_when_virtual_needed(self):
self.assert_multi_line_lint_re(
'''\
@@ -4213,6 +4266,18 @@
' 0,\n'
' 1\n'
'};', '')
+ self.assert_multi_line_lint(
+ 'ENUM_CLASS(CPP11EnumClass)\n'
+ '{\n'
+ ' Value1,\n'
+ ' Value2\n'
+ '};',
+ 'This { should be at the end of the previous line [whitespace/braces] [4]')
+ self.assert_multi_line_lint(
+ 'ENUM_CLASS(CPP11EnumClass) {\n'
+ ' Value1,\n'
+ ' Value2\n'
+ '};', '')
# 3. One-line control clauses should not use braces unless
# comments are included or a single statement spans multiple