Changeset 53841 in webkit
- Timestamp:
- Jan 25, 2010 11:36:48 PM (14 years ago)
- Location:
- trunk/WebKitTools
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKitTools/ChangeLog
r53837 r53841 1 2010-01-25 Chris Jerdonek <cjerdonek@webkit.org> 2 3 Reviewed by Shinichiro Hamaji. 4 5 Refactored check-webkit-style by removing the file path 6 parameter from the style error handler functions. 7 8 https://bugs.webkit.org/show_bug.cgi?id=34031 9 10 * Scripts/webkitpy/style/checker.py: 11 - Added _default_style_error_handler() to StyleChecker class. 12 - Moved handle_style_error() to inside _default_style_error_handler(). 13 14 * Scripts/webkitpy/style/checker_unittest.py: 15 - Removed file path from calls to error handler. 16 17 * Scripts/webkitpy/style/cpp_style.py: 18 - Removed file path from calls to error handler. 19 20 * Scripts/webkitpy/style/cpp_style_unittest.py: 21 - Removed file path from calls to error handler. 22 23 * Scripts/webkitpy/style/text_style.py: 24 - Removed file path from calls to error handler. 25 26 * Scripts/webkitpy/style/text_style_unittest.py: 27 - Removed file path from calls to error handler. 28 1 29 2010-01-25 Jeremy Orlow <jorlow@chromium.org> 2 30 -
trunk/WebKitTools/Scripts/webkitpy/style/checker.py
r53730 r53841 772 772 self.options = options 773 773 774 def _handle_style_error(self, filename, line_number, category, confidence, message): 775 """Handle the occurrence of a style error while checking. 776 777 Check whether an error should be reported. If so, increment the 778 global error count and report the error details. 774 def _default_style_error_handler(self, file_path): 775 """Return a default style error handler for the given path. 779 776 780 777 Args: 781 filename: The name of the file containing the error. 782 line_number: The number of the line containing the error. 783 category: A string used to describe the "category" this bug 784 falls under: "whitespace", say, or "runtime". 785 Categories may have a hierarchy separated by slashes: 786 "whitespace/indent". 787 confidence: A number from 1-5 representing a confidence score 788 for the error, with 5 meaning that we are certain 789 of the problem, and 1 meaning that it could be a 790 legitimate construct. 791 message: The error message. 792 793 """ 794 if not self.options.should_report_error(category, confidence): 795 return 796 797 self.error_count += 1 798 799 if self.options.output_format == 'vs7': 800 format_string = "%s(%s): %s [%s] [%d]\n" 801 else: 802 format_string = "%s:%s: %s [%s] [%d]\n" 803 804 self._stderr_write(format_string % (filename, line_number, message, 805 category, confidence)) 778 file_path: The path to the file containing the error. This 779 is meant for reporting to the user. 780 781 """ 782 def handle_style_error(line_number, category, confidence, message): 783 """Handle the occurrence of a style error. 784 785 Check whether an error should be reported. If so, increment the 786 global error count and report the error details. 787 788 Args: 789 line_number: The number of the line containing the error. 790 category: A string used to describe the "category" this bug 791 falls under: "whitespace", say, or "runtime". 792 Categories may have a hierarchy separated by slashes: 793 "whitespace/indent". 794 confidence: A number from 1-5 representing a confidence score 795 for the error, with 5 meaning that we are certain 796 of the problem, and 1 meaning that it could be a 797 legitimate construct. 798 message: The error message. 799 800 """ 801 if not self.options.should_report_error(category, confidence): 802 return 803 804 self.error_count += 1 805 806 if self.options.output_format == 'vs7': 807 format_string = "%s(%s): %s [%s] [%d]\n" 808 else: 809 format_string = "%s:%s: %s [%s] [%d]\n" 810 811 self._stderr_write(format_string % (file_path, 812 line_number, 813 message, 814 category, 815 confidence)) 816 return handle_style_error 806 817 807 818 def _process_file(self, processor, file_path, handle_style_error): … … 863 874 """ 864 875 if handle_style_error is None: 865 handle_style_error = self._ handle_style_error876 handle_style_error = self._default_style_error_handler(file_path) 866 877 867 878 if process_file is None: … … 897 908 line_numbers = set() 898 909 899 def error_for_patch(file_path, line_number, category, confidence, message): 910 handle_style_error = self._default_style_error_handler(file_path) 911 912 def handle_patch_style_error(line_number, category, confidence, 913 message): 900 914 """Wrapper function of cpp_style.error for patches. 901 915 … … 914 928 # logged -- like carriage-return errors. 915 929 if line_number in line_numbers: 916 self._handle_style_error(file_path,line_number, category, confidence, message)917 918 self.check_file(file_path, handle_ style_error=error_for_patch)919 930 handle_style_error(line_number, category, confidence, message) 931 932 self.check_file(file_path, handle_patch_style_error) 933 -
trunk/WebKitTools/Scripts/webkitpy/style/checker_unittest.py
r53675 r53841 550 550 def write_sample_error(self, style_checker, error_confidence): 551 551 """Write an error to the given style checker.""" 552 style_checker._handle_style_error(filename="filename", 553 line_number=1, 554 category="category", 555 confidence=error_confidence, 556 message="message") 557 558 def test_handle_style_error(self): 552 handle_style_error = ( 553 style_checker._default_style_error_handler("filename")) 554 555 handle_style_error(line_number=1, 556 category="category", 557 confidence=error_confidence, 558 message="message") 559 560 def test_default_style_error_handler(self): 559 561 """Test _handle_style_error() function.""" 560 562 options = ProcessorOptions(output_format="emacs", -
trunk/WebKitTools/Scripts/webkitpy/style/cpp_style.py
r53675 r53841 295 295 if error_level > 5: 296 296 error_level = 5 297 error( filename,line_number, 'readability/fn_size', error_level,297 error(line_number, 'readability/fn_size', error_level, 298 298 'Small and focused functions are preferred:' 299 299 ' %s has %d non-comment lines' … … 473 473 line_index_end = find_next_multi_line_comment_end(lines, line_index_begin) 474 474 if line_index_end >= len(lines): 475 error( filename,line_index_begin + 1, 'readability/multiline_comment', 5,475 error(line_index_begin + 1, 'readability/multiline_comment', 5, 476 476 'Could not find end of multi-line comment') 477 477 return … … 592 592 break 593 593 else: # means no copyright line was found 594 error( filename,0, 'legal/copyright', 5,594 error(0, 'legal/copyright', 5, 595 595 'No copyright message found. ' 596 596 'You should have a line: "Copyright [year] <Copyright Owner>"') … … 643 643 644 644 if not ifndef or not define or ifndef != define: 645 error( filename,0, 'build/header_guard', 5,645 error(0, 'build/header_guard', 5, 646 646 'No #ifndef header guard found, suggested CPP variable is: %s' % 647 647 cppvar) … … 650 650 # The guard should be File_h. 651 651 if ifndef != cppvar: 652 error( filename,ifndef_line_number, 'build/header_guard', 5,652 error(ifndef_line_number, 'build/header_guard', 5, 653 653 '#ifndef header guard has wrong style, please use: %s' % cppvar) 654 654 … … 669 669 for line_number, line in enumerate(lines): 670 670 if u'\ufffd' in line: 671 error( filename,line_number, 'readability/utf8', 5,671 error(line_number, 'readability/utf8', 5, 672 672 'Line contains invalid UTF-8 (or Unicode replacement character).') 673 673 … … 687 687 # last-but-two element of lines() exists and is empty. 688 688 if len(lines) < 3 or lines[-2]: 689 error( filename,len(lines) - 2, 'whitespace/ending_newline', 5,689 error(len(lines) - 2, 'whitespace/ending_newline', 5, 690 690 'Could not find a newline character at the end of the file.') 691 691 … … 715 715 716 716 if line.count('/*') > line.count('*/'): 717 error( filename,line_number, 'readability/multiline_comment', 5,717 error(line_number, 'readability/multiline_comment', 5, 718 718 'Complex multi-line /*...*/-style comment found. ' 719 719 'Lint may give bogus warnings. ' … … 723 723 724 724 if (line.count('"') - line.count('\\"')) % 2: 725 error( filename,line_number, 'readability/multiline_string', 5,725 error(line_number, 'readability/multiline_string', 5, 726 726 'Multi-line string ("...") found. This lint script doesn\'t ' 727 727 'do well with such strings, and may give bogus warnings. They\'re ' … … 767 767 if index >= 0 and (index == 0 or (not line[index - 1].isalnum() 768 768 and line[index - 1] not in ('_', '.', '>'))): 769 error( filename,line_number, 'runtime/threadsafe_fn', 2,769 error(line_number, 'runtime/threadsafe_fn', 2, 770 770 'Consider using ' + multithread_safe_function + 771 771 '...) instead of ' + single_thread_function + … … 797 797 line = clean_lines.elided[line_number] 798 798 if _RE_PATTERN_INVALID_INCREMENT.match(line): 799 error( filename,line_number, 'runtime/invalid_increment', 5,799 error(line_number, 'runtime/invalid_increment', 5, 800 800 'Changing pointer instead of value (or unused value of operator*).') 801 801 … … 838 838 # get in the way of brace matching. See the testBuildClass test in 839 839 # cpp_style_unittest.py for an example of this. 840 error( filename,self.classinfo_stack[0].line_number, 'build/class', 5,840 error(self.classinfo_stack[0].line_number, 'build/class', 5, 841 841 'Failed to find complete declaration of class %s' % 842 842 self.classinfo_stack[0].name) … … 887 887 888 888 if search(r'printf\s*\(.*".*%[-+ ]?\d*q', line): 889 error( filename,line_number, 'runtime/printf_format', 3,889 error(line_number, 'runtime/printf_format', 3, 890 890 '%q in format strings is deprecated. Use %ll instead.') 891 891 892 892 if search(r'printf\s*\(.*".*%\d+\$', line): 893 error( filename,line_number, 'runtime/printf_format', 2,893 error(line_number, 'runtime/printf_format', 2, 894 894 '%N$ formats are unconventional. Try rewriting to avoid them.') 895 895 … … 898 898 899 899 if search(r'("|\').*\\(%|\[|\(|{)', line): 900 error( filename,line_number, 'build/printf_format', 3,900 error(line_number, 'build/printf_format', 3, 901 901 '%, [, (, and { are undefined character escapes. Unescape them.') 902 902 … … 909 909 r'\s+(auto|register|static|extern|typedef)\b', 910 910 line): 911 error( filename,line_number, 'build/storage_class', 5,911 error(line_number, 'build/storage_class', 5, 912 912 'Storage class (static, extern, typedef, etc) should be first.') 913 913 914 914 if match(r'\s*#\s*endif\s*[^/\s]+', line): 915 error( filename,line_number, 'build/endif_comment', 5,915 error(line_number, 'build/endif_comment', 5, 916 916 'Uncommented text after #endif is non-standard. Use a comment.') 917 917 918 918 if match(r'\s*class\s+(\w+\s*::\s*)+\w+\s*;', line): 919 error( filename,line_number, 'build/forward_decl', 5,919 error(line_number, 'build/forward_decl', 5, 920 920 'Inner-style forward declarations are invalid. Remove this line.') 921 921 922 922 if search(r'(\w+|[+-]?\d+(\.\d*)?)\s*(<|>)\?=?\s*(\w+|[+-]?\d+)(\.\d*)?', line): 923 error( filename,line_number, 'build/deprecated', 3,923 error(line_number, 'build/deprecated', 3, 924 924 '>? and <? (max and min) operators are non-standard and deprecated.') 925 925 … … 971 971 and not match(r'(const\s+)?%s\s*&' % re.escape(base_classname), 972 972 args.group(1).strip())): 973 error( filename,line_number, 'runtime/explicit', 5,973 error(line_number, 'runtime/explicit', 5, 974 974 'Single-argument constructors should be marked explicit.') 975 975 … … 996 996 and (not classinfo.has_virtual_destructor) 997 997 and (not classinfo.is_derived)): # Only warn for base classes 998 error( filename,classinfo.line_number, 'runtime/virtual', 4,998 error(classinfo.line_number, 'runtime/virtual', 4, 999 999 'The class %s probably needs a virtual destructor due to ' 1000 1000 'having virtual method(s), one declared at line %d.' … … 1049 1049 and not search(r' \([^)]+\)\[[^\]]+\]', function_call)): 1050 1050 if search(r'\w\s*\([ \t](?!\s*\\$)', function_call): # a ( used for a fn call 1051 error( filename,line_number, 'whitespace/parens', 4,1051 error(line_number, 'whitespace/parens', 4, 1052 1052 'Extra space after ( in function call') 1053 1053 elif search(r'\([ \t]+(?!(\s*\\)|\()', function_call): 1054 error( filename,line_number, 'whitespace/parens', 2,1054 error(line_number, 'whitespace/parens', 2, 1055 1055 'Extra space after (') 1056 1056 if (search(r'\w\s+\(', function_call) 1057 1057 and not search(r'#\s*define|typedef', function_call)): 1058 error( filename,line_number, 'whitespace/parens', 4,1058 error(line_number, 'whitespace/parens', 4, 1059 1059 'Extra space before ( in function call') 1060 1060 # If the ) is followed only by a newline or a { + newline, assume it's 1061 1061 # part of a control statement (if/while/etc), and don't complain 1062 1062 if search(r'[^)\s]\s+\)(?!\s*$|{\s*$)', function_call): 1063 error( filename,line_number, 'whitespace/parens', 2,1063 error(line_number, 'whitespace/parens', 2, 1064 1064 'Extra space before )') 1065 1065 … … 1140 1140 if not body_found: 1141 1141 # No body for the function (or evidence of a non-function) was found. 1142 error( filename,line_number, 'readability/fn_size', 5,1142 error(line_number, 'readability/fn_size', 5, 1143 1143 'Lint failed to find start of function body.') 1144 1144 elif match(r'^\}\s*$', line): # function end … … 1211 1211 1212 1212 if not exception: 1213 error( filename,line_number, 'whitespace/blank_line', 2,1213 error(line_number, 'whitespace/blank_line', 2, 1214 1214 'Blank line at the start of a code block. Is this needed?') 1215 1215 # This doesn't ignore whitespace at the end of a namespace block … … 1232 1232 and next_line.find('namespace') == -1 1233 1233 and next_line.find('} else ') == -1): 1234 error( filename,line_number, 'whitespace/blank_line', 3,1234 error(line_number, 'whitespace/blank_line', 3, 1235 1235 'Blank line at the end of a code block. Is this needed?') 1236 1236 … … 1247 1247 or (comment_position >= 2 1248 1248 and line[comment_position - 2] in string.whitespace)))): 1249 error( filename,line_number, 'whitespace/comments', 5,1249 error(line_number, 'whitespace/comments', 5, 1250 1250 'One space before end of line comments') 1251 1251 # There should always be a space between the // and the comment … … 1260 1260 or search(r'^/+ ', line[commentend:])) 1261 1261 if not matched: 1262 error( filename,line_number, 'whitespace/comments', 4,1262 error(line_number, 'whitespace/comments', 4, 1263 1263 'Should have a space between // and comment') 1264 1264 … … 1272 1272 return 1273 1273 if search(r'[\w.]=[\w.]', line): 1274 error( filename,line_number, 'whitespace/operators', 4,1274 error(line_number, 'whitespace/operators', 4, 1275 1275 'Missing spaces around =') 1276 1276 … … 1290 1290 matched = search(r'[^<>=!\s](<)[^<>=!\s]([^>]|->)*$', line) 1291 1291 if matched: 1292 error( filename,line_number, 'whitespace/operators', 3,1292 error(line_number, 'whitespace/operators', 3, 1293 1293 'Missing spaces around %s' % matched.group(1)) 1294 1294 … … 1296 1296 matched = search(r'(!\s|~\s|[\s]--[\s;]|[\s]\+\+[\s;])', line) 1297 1297 if matched: 1298 error( filename,line_number, 'whitespace/operators', 4,1298 error(line_number, 'whitespace/operators', 4, 1299 1299 'Extra space for operator %s' % matched.group(1)) 1300 1300 … … 1302 1302 matched = search(r' (if\(|for\(|foreach\(|while\(|switch\()', line) 1303 1303 if matched: 1304 error( filename,line_number, 'whitespace/parens', 5,1304 error(line_number, 'whitespace/parens', 5, 1305 1305 'Missing space before ( in %s' % matched.group(1)) 1306 1306 … … 1317 1317 and len(matched.group(2)) == 1 + len(matched.group(4)) 1318 1318 or not matched.group(2) and search(r'\bfor\s*\(.*; \)', line)): 1319 error( filename,line_number, 'whitespace/parens', 5,1319 error(line_number, 'whitespace/parens', 5, 1320 1320 'Mismatching spaces inside () in %s' % matched.group(1)) 1321 1321 if not len(matched.group(2)) in [0, 1]: 1322 error( filename,line_number, 'whitespace/parens', 5,1322 error(line_number, 'whitespace/parens', 5, 1323 1323 'Should have zero or one spaces inside ( and ) in %s' % 1324 1324 matched.group(1)) … … 1326 1326 # You should always have a space after a comma (either as fn arg or operator) 1327 1327 if search(r',[^\s]', line): 1328 error( filename,line_number, 'whitespace/comma', 3,1328 error(line_number, 'whitespace/comma', 3, 1329 1329 'Missing space after ,') 1330 1330 … … 1333 1333 matched = match(r'\s*\w+(?<!\breturn)\s+(?P<pointer_operator>\*|\&)\w+', line) 1334 1334 if matched: 1335 error( filename,line_number, 'whitespace/declaration', 3,1335 error(line_number, 'whitespace/declaration', 3, 1336 1336 'Declaration has space between type name and %s in %s' % (matched.group('pointer_operator'), matched.group(0).strip())) 1337 1337 … … 1340 1340 matched = search(r'^\s*\w+\*\s+\w+', line) 1341 1341 if matched: 1342 error( filename,line_number, 'whitespace/declaration', 3,1342 error(line_number, 'whitespace/declaration', 3, 1343 1343 'Declaration has space between * and variable name in %s' % matched.group(0).strip()) 1344 1344 … … 1350 1350 # an easy test. 1351 1351 if search(r'[^ ({]{', line): 1352 error( filename,line_number, 'whitespace/braces', 5,1352 error(line_number, 'whitespace/braces', 5, 1353 1353 'Missing space before {') 1354 1354 1355 1355 # Make sure '} else {' has spaces. 1356 1356 if search(r'}else', line): 1357 error( filename,line_number, 'whitespace/braces', 5,1357 error(line_number, 'whitespace/braces', 5, 1358 1358 'Missing space before else') 1359 1359 … … 1361 1361 # 'delete []' or 'new char * []'. 1362 1362 if search(r'\w\s+\[', line) and not search(r'delete\s+\[', line): 1363 error( filename,line_number, 'whitespace/braces', 5,1363 error(line_number, 'whitespace/braces', 5, 1364 1364 'Extra space before [') 1365 1365 … … 1368 1368 # the semicolon there. 1369 1369 if search(r':\s*;\s*$', line): 1370 error( filename,line_number, 'whitespace/semicolon', 5,1370 error(line_number, 'whitespace/semicolon', 5, 1371 1371 'Semicolon defining empty statement. Use { } instead.') 1372 1372 elif search(r'^\s*;\s*$', line): 1373 error( filename,line_number, 'whitespace/semicolon', 5,1373 error(line_number, 'whitespace/semicolon', 5, 1374 1374 'Line contains only semicolon. If this should be an empty statement, ' 1375 1375 'use { } instead.') 1376 1376 elif (search(r'\s+;\s*$', line) and not search(r'\bfor\b', line)): 1377 error( filename,line_number, 'whitespace/semicolon', 5,1377 error(line_number, 'whitespace/semicolon', 5, 1378 1378 'Extra space before last semicolon. If this should be an empty ' 1379 1379 'statement, use { } instead.') … … 1382 1382 # Allow do {} while(); 1383 1383 and not search(r'}\s*while', line)): 1384 error( filename,line_number, 'whitespace/semicolon', 5,1384 error(line_number, 'whitespace/semicolon', 5, 1385 1385 'Semicolon defining empty statement for this loop. Use { } instead.') 1386 1386 … … 1432 1432 # Don't warn about an indented namespace if we already warned about indented code. 1433 1433 if not file_state.did_inside_namespace_indent_warning(): 1434 error( filename,line_number, 'whitespace/indent', 4,1434 error(line_number, 'whitespace/indent', 4, 1435 1435 'namespace should never be indented.') 1436 1436 return … … 1446 1446 if not match(r'\S', current_line) and not file_state.did_inside_namespace_indent_warning(): 1447 1447 file_state.set_did_inside_namespace_indent_warning() 1448 error( filename,line_number + line_offset, 'whitespace/indent', 4,1448 error(line_number + line_offset, 'whitespace/indent', 4, 1449 1449 'Code inside a namespace should not be indented.') 1450 1450 if in_preprocessor_directive or (current_line.strip()[0] == '#'): # This takes care of preprocessor directive syntax. … … 1479 1479 1480 1480 method_name = using_std_match.group('method_name') 1481 error( filename,line_number, 'build/using_std', 4,1481 error(line_number, 'build/using_std', 4, 1482 1482 "Use 'using namespace std;' instead of 'using std::%s;'." % method_name) 1483 1483 … … 1505 1505 max_min_macro = max_min_macros_search.group('max_min_macro') 1506 1506 max_min_macro_lower = max_min_macro.lower() 1507 error( filename,line_number, 'runtime/max_min_macros', 4,1507 error(line_number, 'runtime/max_min_macros', 4, 1508 1508 'Use std::%s() or std::%s<type>() instead of the %s() macro.' 1509 1509 % (max_min_macro_lower, max_min_macro_lower, max_min_macro)) … … 1560 1560 elif match(r'(default|case\s+.*)\s*:([^:].*)?$', remaining_line): 1561 1561 if current_indentation != switch_indentation: 1562 error( filename,line_number + line_offset, 'whitespace/indent', 4,1562 error(line_number + line_offset, 'whitespace/indent', 4, 1563 1563 'A case label should not be indented, but line up with its switch statement.') 1564 1564 # Don't throw an error for multiple badly indented labels, … … 1571 1571 # the switch statement plus one more level of indentation. 1572 1572 elif not current_indentation.startswith(inner_indentation): 1573 error( filename,line_number + line_offset, 'whitespace/indent', 4,1573 error(line_number + line_offset, 'whitespace/indent', 4, 1574 1574 'Non-label code inside switch statements should be indented.') 1575 1575 # Don't throw an error for multiple badly indented statements, … … 1606 1606 or search(r'\b(if|for|foreach|while|switch|else)\b', previous_line)) 1607 1607 and previous_line.find('#') < 0): 1608 error( filename,line_number, 'whitespace/braces', 4,1608 error(line_number, 'whitespace/braces', 4, 1609 1609 'This { should be at the end of the previous line') 1610 1610 elif (search(r'\)\s*(const\s*)?{\s*$', line) … … 1612 1612 and not search(r'\b(if|for|foreach|while|switch)\b', line) 1613 1613 and not match(r'\s+[A-Z_][A-Z_0-9]+\b', line)): 1614 error( filename,line_number, 'whitespace/braces', 4,1614 error(line_number, 'whitespace/braces', 4, 1615 1615 'Place brace on its own line for function definitions.') 1616 1616 … … 1621 1621 if (previous_line.find('{') > 0 1622 1622 and search(r'\b(if|for|foreach|while|else)\b', previous_line)): 1623 error( filename,line_number, 'whitespace/braces', 4,1623 error(line_number, 'whitespace/braces', 4, 1624 1624 'One line control clauses should not use braces.') 1625 1625 … … 1628 1628 previous_line = get_previous_non_blank_line(clean_lines, line_number)[0] 1629 1629 if match(r'\s*}\s*$', previous_line): 1630 error( filename,line_number, 'whitespace/newline', 4,1630 error(line_number, 'whitespace/newline', 4, 1631 1631 'An else should appear on the same line as the preceding }') 1632 1632 1633 1633 # Likewise, an else should never have the else clause on the same line 1634 1634 if search(r'\belse [^\s{]', line) and not search(r'\belse if\b', line): 1635 error( filename,line_number, 'whitespace/newline', 4,1635 error(line_number, 'whitespace/newline', 4, 1636 1636 'Else clause should never be on same line as else (use 2 lines)') 1637 1637 1638 1638 # In the same way, a do/while should never be on one line 1639 1639 if match(r'\s*do [^\s{]', line): 1640 error( filename,line_number, 'whitespace/newline', 4,1640 error(line_number, 'whitespace/newline', 4, 1641 1641 'do/while clauses should not be on a single line') 1642 1642 … … 1654 1654 and line.count('{') == line.count('}') 1655 1655 and not search(r'struct|class|enum|\s*=\s*{', line)): 1656 error( filename,line_number, 'readability/braces', 4,1656 error(line_number, 'readability/braces', 4, 1657 1657 "You don't need a ; after a }") 1658 1658 … … 1737 1737 if match(r'if\s*\(', remaining_line): 1738 1738 if else_match.start('else') != -1: 1739 error( filename,line_number + line_offset, 'readability/control_flow', 4,1739 error(line_number + line_offset, 'readability/control_flow', 4, 1740 1740 'An else statement can be removed when the prior "if" ' 1741 1741 'concludes with a return, break, continue or goto statement.') 1742 1742 else: 1743 error( filename,line_number + line_offset, 'readability/control_flow', 4,1743 error(line_number + line_offset, 'readability/control_flow', 4, 1744 1744 'An else if statement should be written as an if statement ' 1745 1745 'when the prior "if" concludes with a return, break, ' … … 1809 1809 for operator in ['==', '!=', '>=', '>', '<=', '<']: 1810 1810 if replaceable_check(operator, current_macro, line): 1811 error( filename,line_number, 'readability/check', 2,1811 error(line_number, 'readability/check', 2, 1812 1812 'Consider using %s instead of %s(a %s b)' % ( 1813 1813 _CHECK_REPLACEMENT[current_macro][operator], … … 1822 1822 # Include NULL here so that users don't have to convert NULL to 0 first and then get this error. 1823 1823 if search(r'[=!]=\s*(NULL|0|true|false)\W', line) or search(r'\W(NULL|0|true|false)\s*[=!]=', line): 1824 error( filename,line_number, 'readability/comparison_to_zero', 5,1824 error(line_number, 'readability/comparison_to_zero', 5, 1825 1825 'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.') 1826 1826 … … 1838 1838 1839 1839 if search(r'\bNULL\b', line): 1840 error( filename,line_number, 'readability/null', 5, 'Use 0 instead of NULL.')1840 error(line_number, 'readability/null', 5, 'Use 0 instead of NULL.') 1841 1841 return 1842 1842 … … 1846 1846 # NULLs occurring in strings. 1847 1847 if search(r'\bNULL\b', line) and search(r'\bNULL\b', CleansedLines.collapse_strings(line)): 1848 error( filename,line_number, 'readability/null', 4, 'Use 0 instead of NULL.')1848 error(line_number, 'readability/null', 4, 'Use 0 instead of NULL.') 1849 1849 1850 1850 def get_line_width(line): … … 1890 1890 1891 1891 if line.find('\t') != -1: 1892 error( filename,line_number, 'whitespace/tab', 1,1892 error(line_number, 'whitespace/tab', 1, 1893 1893 'Tab found; better to use spaces') 1894 1894 … … 1910 1910 initial_spaces += 1 1911 1911 if line and line[-1].isspace(): 1912 error( filename,line_number, 'whitespace/end_of_line', 4,1912 error(line_number, 'whitespace/end_of_line', 4, 1913 1913 'Line ends in whitespace. Consider deleting these extra spaces.') 1914 1914 # There are certain situations we allow one space, notably for labels 1915 1915 elif ((initial_spaces >= 1 and initial_spaces <= 3) 1916 1916 and not match(r'\s*\w+\s*:\s*$', cleansed_line)): 1917 error( filename,line_number, 'whitespace/indent', 3,1917 error(line_number, 'whitespace/indent', 3, 1918 1918 'Weird number of spaces at line-start. ' 1919 1919 'Are you using a 4-space indent?') … … 1927 1927 # because goto labels can in fact occur at the start of the line. 1928 1928 if label in ['public', 'private', 'protected'] or label.find(' ') != -1: 1929 error( filename,line_number, 'whitespace/labels', 4,1929 error(line_number, 'whitespace/labels', 4, 1930 1930 'Labels should always be indented at least one space. ' 1931 1931 'If this is a member-initializer list in a constructor, ' … … 1942 1942 and cleansed_line.find('break;') != -1) 1943 1943 and not cleansed_line.startswith('#define ')): 1944 error( filename,line_number, 'whitespace/newline', 4,1944 error(line_number, 'whitespace/newline', 4, 1945 1945 'More than one command on the same line') 1946 1946 1947 1947 if cleansed_line.strip().endswith('||') or cleansed_line.strip().endswith('&&'): 1948 error( filename,line_number, 'whitespace/operators', 4,1948 error(line_number, 'whitespace/operators', 4, 1949 1949 'Boolean expressions that span multiple lines should have their ' 1950 1950 'operators on the left side of the line instead of the right side.') … … 2116 2116 # Many unit tests use cout, so we exempt them. 2117 2117 if not _is_test_filename(filename): 2118 error( filename,line_number, 'readability/streams', 3,2118 error(line_number, 'readability/streams', 3, 2119 2119 'Streams are highly discouraged.') 2120 2120 2121 2121 # Look for specific includes to fix. 2122 2122 if include.startswith('wtf/') and not is_system: 2123 error( filename,line_number, 'build/include', 4,2123 error(line_number, 'build/include', 4, 2124 2124 'wtf includes should be <wtf/file.h> instead of "wtf/file.h".') 2125 2125 2126 2126 duplicate_header = include in include_state 2127 2127 if duplicate_header: 2128 error( filename,line_number, 'build/include', 4,2128 error(line_number, 'build/include', 4, 2129 2129 '"%s" already included at %s:%s' % 2130 2130 (include, filename, include_state[include])) … … 2150 2150 next_line = clean_lines.raw_lines[line_number + 1] 2151 2151 if not is_blank_line(next_line): 2152 error( filename,line_number, 'build/include_order', 4,2152 error(line_number, 'build/include_order', 4, 2153 2153 'You should add a blank line after implementation file\'s own header.') 2154 2154 … … 2167 2167 previous_header_type = include_state.header_types[previous_line_number] 2168 2168 if previous_header_type == _OTHER_HEADER and previous_line.strip() > line.strip(): 2169 error( filename,line_number, 'build/include_order', 4,2169 error(line_number, 'build/include_order', 4, 2170 2170 'Alphabetical sorting problem.') 2171 2171 2172 2172 if error_message: 2173 2173 if filename.endswith('.h'): 2174 error( filename,line_number, 'build/include_order', 4,2174 error(line_number, 'build/include_order', 4, 2175 2175 '%s Should be: alphabetically sorted.' % 2176 2176 error_message) 2177 2177 else: 2178 error( filename,line_number, 'build/include_order', 4,2178 error(line_number, 'build/include_order', 4, 2179 2179 '%s Should be: config.h, primary header, blank line, and then alphabetically sorted.' % 2180 2180 error_message) … … 2220 2220 # virtually indistinguishable from int(x) casts. 2221 2221 if not match(r'^\s*MOCK_(CONST_)?METHOD\d+(_T)?\(', line): 2222 error( filename,line_number, 'readability/casting', 4,2222 error(line_number, 'readability/casting', 4, 2223 2223 'Using deprecated casting style. ' 2224 2224 'Use static_cast<%s>(...) instead' % … … 2238 2238 if search( 2239 2239 r'(&\([^)]+\)[\w(])|(&(static|dynamic|reinterpret)_cast\b)', line): 2240 error( filename,line_number, 'runtime/casting', 4,2240 error(line_number, 'runtime/casting', 4, 2241 2241 ('Are you taking an address of a cast? ' 2242 2242 'This is dangerous: could be a temp var. ' … … 2254 2254 if matched and not match(r'\s*(<.*>)?(::[a-zA-Z0-9_]+)?\s*\(([^"]|$)', 2255 2255 matched.group(3)): 2256 error( filename,line_number, 'runtime/string', 4,2256 error(line_number, 'runtime/string', 4, 2257 2257 'For a static/global string constant, use a C style string instead: ' 2258 2258 '"%schar %s[]".' % … … 2261 2261 # Check that we're not using RTTI outside of testing code. 2262 2262 if search(r'\bdynamic_cast<', line) and not _is_test_filename(filename): 2263 error( filename,line_number, 'runtime/rtti', 5,2263 error(line_number, 'runtime/rtti', 5, 2264 2264 'Do not use dynamic_cast<>. If you need to cast within a class ' 2265 2265 "hierarchy, use static_cast<> to upcast. Google doesn't support " … … 2267 2267 2268 2268 if search(r'\b([A-Za-z0-9_]*_)\(\1\)', line): 2269 error( filename,line_number, 'runtime/init', 4,2269 error(line_number, 'runtime/init', 4, 2270 2270 'You seem to be initializing a member variable with itself.') 2271 2271 … … 2280 2280 if search(r'\bshort port\b', line): 2281 2281 if not search(r'\bunsigned short port\b', line): 2282 error( filename,line_number, 'runtime/int', 4,2282 error(line_number, 'runtime/int', 4, 2283 2283 'Use "unsigned short" for ports, not "short"') 2284 2284 … … 2286 2286 matched = search(r'snprintf\s*\(([^,]*),\s*([0-9]*)\s*,', line) 2287 2287 if matched: 2288 error( filename,line_number, 'runtime/printf', 3,2288 error(line_number, 'runtime/printf', 3, 2289 2289 'If you can, use sizeof(%s) instead of %s as the 2nd arg ' 2290 2290 'to snprintf.' % (matched.group(1), matched.group(2))) … … 2292 2292 # Check if some verboten C functions are being used. 2293 2293 if search(r'\bsprintf\b', line): 2294 error( filename,line_number, 'runtime/printf', 5,2294 error(line_number, 'runtime/printf', 5, 2295 2295 'Never use sprintf. Use snprintf instead.') 2296 2296 matched = search(r'\b(strcpy|strcat)\b', line) 2297 2297 if matched: 2298 error( filename,line_number, 'runtime/printf', 4,2298 error(line_number, 'runtime/printf', 4, 2299 2299 'Almost always, snprintf is better than %s' % matched.group(1)) 2300 2300 2301 2301 if search(r'\bsscanf\b', line): 2302 error( filename,line_number, 'runtime/printf', 1,2302 error(line_number, 'runtime/printf', 1, 2303 2303 'sscanf can be ok, but is slow and can overflow buffers.') 2304 2304 … … 2306 2306 # } if (a == b) { 2307 2307 if search(r'\}\s*if\s*\(', line): 2308 error( filename,line_number, 'readability/braces', 4,2308 error(line_number, 'readability/braces', 4, 2309 2309 'Did you mean "else if"? If not, start a new line for "if".') 2310 2310 … … 2314 2314 matched = re.search(r'\b((?:string)?printf)\s*\(([\w.\->()]+)\)', line, re.I) 2315 2315 if matched: 2316 error( filename,line_number, 'runtime/printf', 4,2316 error(line_number, 'runtime/printf', 4, 2317 2317 'Potential format string bug. Do %s("%%s", %s) instead.' 2318 2318 % (matched.group(1), matched.group(2))) … … 2321 2321 matched = search(r'memset\s*\(([^,]*),\s*([^,]*),\s*0\s*\)', line) 2322 2322 if matched and not match(r"^''|-?[0-9]+|0x[0-9A-Fa-f]$", matched.group(2)): 2323 error( filename,line_number, 'runtime/memset', 4,2323 error(line_number, 'runtime/memset', 4, 2324 2324 'Did you mean "memset(%s, 0, %s)"?' 2325 2325 % (matched.group(1), matched.group(2))) … … 2368 2368 break 2369 2369 if not is_const: 2370 error( filename,line_number, 'runtime/arrays', 1,2370 error(line_number, 'runtime/arrays', 1, 2371 2371 'Do not use variable-length arrays. Use an appropriately named ' 2372 2372 "('k' followed by CamelCase) compile-time constant for the size.") … … 2378 2378 and search(r'\bnamespace\s*{', line) 2379 2379 and line[-1] != '\\'): 2380 error( filename,line_number, 'build/namespaces', 4,2380 error(line_number, 'build/namespaces', 4, 2381 2381 'Do not use unnamed namespaces in header files. See ' 2382 2382 'http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces' … … 2477 2477 and not modified_identifier.find('::qt_') >= 0 2478 2478 and not modified_identifier == "const_iterator"): 2479 error( filename,line_number, 'readability/naming', 4, identifier + " is incorrectly named. Don't use underscores in your identifier names.")2479 error(line_number, 'readability/naming', 4, identifier + " is incorrectly named. Don't use underscores in your identifier names.") 2480 2480 2481 2481 # There can be only one declaration in non-for-control statements. … … 2515 2515 sizeof_match = match(r'.*sizeof\s*$', line[0:matched.start(1) - 1]) 2516 2516 if sizeof_match: 2517 error( filename,line_number, 'runtime/sizeof', 1,2517 error(line_number, 'runtime/sizeof', 1, 2518 2518 'Using sizeof(type). Use sizeof(varname) instead if possible') 2519 2519 return … … 2537 2537 or function_match.group(3) == ';' 2538 2538 or raw_line.find('/*') < 0): 2539 error( filename,line_number, 'readability/function', 3,2539 error(line_number, 'readability/function', 3, 2540 2540 'All parameters should be named in a function') 2541 2541 return 2542 2542 2543 2543 # At this point, all that should be left is actual casts. 2544 error( filename,line_number, 'readability/casting', 4,2544 error(line_number, 'readability/casting', 4, 2545 2545 'Using C-style cast. Use %s<%s>(...) instead' % 2546 2546 (cast_type, matched.group(1))) … … 2782 2782 continue 2783 2783 if required_header_unstripped.strip('<>"') not in include_state: 2784 error( filename,required[required_header_unstripped][0],2784 error(required[required_header_unstripped][0], 2785 2785 'build/include_what_you_use', 4, 2786 2786 'Add #include ' + required_header_unstripped + ' for ' + template) -
trunk/WebKitTools/Scripts/webkitpy/style/cpp_style_unittest.py
r53675 r53841 63 63 self._errors = [] 64 64 65 def __call__(self, unused_filename, unused_linenum, 66 category, confidence, message): 65 def __call__(self, unused_linenum, category, confidence, message): 67 66 self._assert_fn(category in self._all_style_categories, 68 67 'Message "%s" has category "%s",' -
trunk/WebKitTools/Scripts/webkitpy/style/text_style.py
r53675 r53841 45 45 for line_number, line in enumerate(lines): 46 46 if "\t" in line: 47 self.handle_style_error( self.file_path,line_number,47 self.handle_style_error(line_number, 48 48 "whitespace/tab", 5, 49 49 "Line contains tab character.") -
trunk/WebKitTools/Scripts/webkitpy/style/text_style_unittest.py
r53675 r53841 42 42 self.had_error = False 43 43 44 def error_for_test( filename,line_number, category, confidence, message):44 def error_for_test(line_number, category, confidence, message): 45 45 """Records if an error occurs.""" 46 46 self.had_error = True … … 53 53 self.had_error = False 54 54 55 def error_for_test( filename,line_number, category, confidence, message):55 def error_for_test(line_number, category, confidence, message): 56 56 """Checks if the expected error occurs.""" 57 57 self.assertEquals(expected_line_number, line_number)
Note: See TracChangeset
for help on using the changeset viewer.