Changeset 46294 in webkit
- Timestamp:
- Jul 23, 2009 3:53:47 PM (15 years ago)
- Location:
- trunk/WebKitTools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKitTools/ChangeLog
r46292 r46294 1 2009-07-23 Jakob Petsovits <jakob.petsovits@torchmobile.com> 2 3 Reviewed by Adam Treat. 4 5 Fix false positives for switch statement indentation check in cpplint. 6 https://bugs.webkit.org/show_bug.cgi?id=27615 7 8 Makes one-line case statements (e.g. "case foo: bar();") work. 9 Also a few general improvements to the robustness and readability of 10 the check, and more test cases. 11 12 * Scripts/modules/cpplint.py: 13 * Scripts/modules/cpplint_unittest.py: 14 1 15 2009-07-23 Jakob Petsovits <jakob.petsovits@torchmobile.com> 2 16 -
trunk/WebKitTools/Scripts/modules/cpplint.py
r46292 r46294 1769 1769 remaining_line = current_indentation_match.group('remaining_line') 1770 1770 1771 if remaining_line.startswith('}'): 1772 break # The end of the switch statement. 1773 elif match(r'(default|case\s+.*)\s*:\s*$', remaining_line): 1771 # End the check at the end of the switch statement. 1772 if remaining_line.startswith('}') and current_indentation == switch_indentation: 1773 break 1774 # Case and default branches should not be indented. The regexp also 1775 # catches single-line cases like "default: break;" but does not trigger 1776 # on stuff like "Document::Foo();". 1777 elif match(r'(default|case\s+.*)\s*:([^:].*)?$', remaining_line): 1774 1778 if current_indentation != switch_indentation: 1775 1779 error(filename, line_number + line_offset, 'whitespace/indent', 4, … … 1778 1782 # one should be enough to figure out the problem. 1779 1783 break 1780 elif not match(r'\w+\s*:\s*$', remaining_line): 1781 # It's not a goto label (which we don't care about), so check if 1782 # it's indented at least as far as the switch plus 4 spaces. 1783 if not current_indentation.startswith(inner_indentation): 1784 error(filename, line_number + line_offset, 'whitespace/indent', 4, 1785 'Non-label code inside switch statements should be indented.') 1786 # Don't throw an error for multiple badly indented statements, 1787 # one should be enough to figure out the problem. 1788 break 1784 # We ignore goto labels at the very beginning of a line. 1785 elif match(r'\w+\s*:\s*$', remaining_line): 1786 continue 1787 # It's not a goto label, so check if it's indented at least as far as 1788 # the switch statement plus one more level of indentation. 1789 elif not current_indentation.startswith(inner_indentation): 1790 error(filename, line_number + line_offset, 'whitespace/indent', 4, 1791 'Non-label code inside switch statements should be indented.') 1792 # Don't throw an error for multiple badly indented statements, 1793 # one should be enough to figure out the problem. 1794 break 1789 1795 1790 1796 if encountered_nested_switch: -
trunk/WebKitTools/Scripts/modules/cpplint_unittest.py
r46292 r46294 2830 2830 self.assert_multi_line_lint( 2831 2831 ' switch (condition) {\n' 2832 ' case fooCondition: break;\n' 2833 ' default: return;\n' 2834 ' }\n', 2835 '') 2836 self.assert_multi_line_lint( 2837 ' switch (condition) {\n' 2832 2838 ' case fooCondition:\n' 2833 2839 ' case barCondition:\n' … … 2835 2841 ' break;\n' 2836 2842 ' default:\n' 2843 ' i--;\n' 2844 ' }\n', 2845 'A case label should not be indented, but line up with its switch statement.' 2846 ' [whitespace/indent] [4]') 2847 self.assert_multi_line_lint( 2848 ' switch (condition) {\n' 2849 ' case fooCondition:\n' 2850 ' break;\n' 2851 ' default:\n' 2837 2852 ' i--;\n' 2838 2853 ' }\n',
Note: See TracChangeset
for help on using the changeset viewer.