Changeset 53841 in webkit


Ignore:
Timestamp:
Jan 25, 2010 11:36:48 PM (14 years ago)
Author:
Chris Jerdonek
Message:

2010-01-25 Chris Jerdonek <Chris Jerdonek>

Reviewed by Shinichiro Hamaji.

Refactored check-webkit-style by removing the file path
parameter from the style error handler functions.

https://bugs.webkit.org/show_bug.cgi?id=34031

  • Scripts/webkitpy/style/checker.py:
    • Added _default_style_error_handler() to StyleChecker class.
    • Moved handle_style_error() to inside _default_style_error_handler().
  • Scripts/webkitpy/style/checker_unittest.py:
    • Removed file path from calls to error handler.
  • Scripts/webkitpy/style/cpp_style.py:
    • Removed file path from calls to error handler.
  • Scripts/webkitpy/style/cpp_style_unittest.py:
    • Removed file path from calls to error handler.
  • Scripts/webkitpy/style/text_style.py:
    • Removed file path from calls to error handler.
  • Scripts/webkitpy/style/text_style_unittest.py:
    • Removed file path from calls to error handler.
Location:
trunk/WebKitTools
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r53837 r53841  
     12010-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
    1292010-01-25  Jeremy Orlow  <jorlow@chromium.org>
    230
  • trunk/WebKitTools/Scripts/webkitpy/style/checker.py

    r53730 r53841  
    772772        self.options = options
    773773
    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.
    779776
    780777        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
    806817
    807818    def _process_file(self, processor, file_path, handle_style_error):
     
    863874        """
    864875        if handle_style_error is None:
    865             handle_style_error = self._handle_style_error
     876            handle_style_error = self._default_style_error_handler(file_path)
    866877
    867878        if process_file is None:
     
    897908            line_numbers = set()
    898909
    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):
    900914                """Wrapper function of cpp_style.error for patches.
    901915
     
    914928                #        logged -- like carriage-return errors.
    915929                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  
    550550    def write_sample_error(self, style_checker, error_confidence):
    551551        """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):
    559561        """Test _handle_style_error() function."""
    560562        options = ProcessorOptions(output_format="emacs",
  • trunk/WebKitTools/Scripts/webkitpy/style/cpp_style.py

    r53675 r53841  
    295295            if error_level > 5:
    296296                error_level = 5
    297             error(filename, line_number, 'readability/fn_size', error_level,
     297            error(line_number, 'readability/fn_size', error_level,
    298298                  'Small and focused functions are preferred:'
    299299                  ' %s has %d non-comment lines'
     
    473473        line_index_end = find_next_multi_line_comment_end(lines, line_index_begin)
    474474        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,
    476476                  'Could not find end of multi-line comment')
    477477            return
     
    592592            break
    593593    else:                       # means no copyright line was found
    594         error(filename, 0, 'legal/copyright', 5,
     594        error(0, 'legal/copyright', 5,
    595595              'No copyright message found.  '
    596596              'You should have a line: "Copyright [year] <Copyright Owner>"')
     
    643643
    644644    if not ifndef or not define or ifndef != define:
    645         error(filename, 0, 'build/header_guard', 5,
     645        error(0, 'build/header_guard', 5,
    646646              'No #ifndef header guard found, suggested CPP variable is: %s' %
    647647              cppvar)
     
    650650    # The guard should be File_h.
    651651    if ifndef != cppvar:
    652         error(filename, ifndef_line_number, 'build/header_guard', 5,
     652        error(ifndef_line_number, 'build/header_guard', 5,
    653653              '#ifndef header guard has wrong style, please use: %s' % cppvar)
    654654
     
    669669    for line_number, line in enumerate(lines):
    670670        if u'\ufffd' in line:
    671             error(filename, line_number, 'readability/utf8', 5,
     671            error(line_number, 'readability/utf8', 5,
    672672                  'Line contains invalid UTF-8 (or Unicode replacement character).')
    673673
     
    687687    # last-but-two element of lines() exists and is empty.
    688688    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,
    690690              'Could not find a newline character at the end of the file.')
    691691
     
    715715
    716716    if line.count('/*') > line.count('*/'):
    717         error(filename, line_number, 'readability/multiline_comment', 5,
     717        error(line_number, 'readability/multiline_comment', 5,
    718718              'Complex multi-line /*...*/-style comment found. '
    719719              'Lint may give bogus warnings.  '
     
    723723
    724724    if (line.count('"') - line.count('\\"')) % 2:
    725         error(filename, line_number, 'readability/multiline_string', 5,
     725        error(line_number, 'readability/multiline_string', 5,
    726726              'Multi-line string ("...") found.  This lint script doesn\'t '
    727727              'do well with such strings, and may give bogus warnings.  They\'re '
     
    767767        if index >= 0 and (index == 0 or (not line[index - 1].isalnum()
    768768                                          and line[index - 1] not in ('_', '.', '>'))):
    769             error(filename, line_number, 'runtime/threadsafe_fn', 2,
     769            error(line_number, 'runtime/threadsafe_fn', 2,
    770770                  'Consider using ' + multithread_safe_function +
    771771                  '...) instead of ' + single_thread_function +
     
    797797    line = clean_lines.elided[line_number]
    798798    if _RE_PATTERN_INVALID_INCREMENT.match(line):
    799         error(filename, line_number, 'runtime/invalid_increment', 5,
     799        error(line_number, 'runtime/invalid_increment', 5,
    800800              'Changing pointer instead of value (or unused value of operator*).')
    801801
     
    838838            # get in the way of brace matching. See the testBuildClass test in
    839839            # 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,
    841841                  'Failed to find complete declaration of class %s' %
    842842                  self.classinfo_stack[0].name)
     
    887887
    888888    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,
    890890              '%q in format strings is deprecated.  Use %ll instead.')
    891891
    892892    if search(r'printf\s*\(.*".*%\d+\$', line):
    893         error(filename, line_number, 'runtime/printf_format', 2,
     893        error(line_number, 'runtime/printf_format', 2,
    894894              '%N$ formats are unconventional.  Try rewriting to avoid them.')
    895895
     
    898898
    899899    if search(r'("|\').*\\(%|\[|\(|{)', line):
    900         error(filename, line_number, 'build/printf_format', 3,
     900        error(line_number, 'build/printf_format', 3,
    901901              '%, [, (, and { are undefined character escapes.  Unescape them.')
    902902
     
    909909              r'\s+(auto|register|static|extern|typedef)\b',
    910910              line):
    911         error(filename, line_number, 'build/storage_class', 5,
     911        error(line_number, 'build/storage_class', 5,
    912912              'Storage class (static, extern, typedef, etc) should be first.')
    913913
    914914    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,
    916916              'Uncommented text after #endif is non-standard.  Use a comment.')
    917917
    918918    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,
    920920              'Inner-style forward declarations are invalid.  Remove this line.')
    921921
    922922    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,
    924924              '>? and <? (max and min) operators are non-standard and deprecated.')
    925925
     
    971971        and not match(r'(const\s+)?%s\s*&' % re.escape(base_classname),
    972972                      args.group(1).strip())):
    973         error(filename, line_number, 'runtime/explicit', 5,
     973        error(line_number, 'runtime/explicit', 5,
    974974              'Single-argument constructors should be marked explicit.')
    975975
     
    996996            and (not classinfo.has_virtual_destructor)
    997997            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,
    999999                  'The class %s probably needs a virtual destructor due to '
    10001000                  'having virtual method(s), one declared at line %d.'
     
    10491049        and not search(r' \([^)]+\)\[[^\]]+\]', function_call)):
    10501050        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,
    10521052                  'Extra space after ( in function call')
    10531053        elif search(r'\([ \t]+(?!(\s*\\)|\()', function_call):
    1054             error(filename, line_number, 'whitespace/parens', 2,
     1054            error(line_number, 'whitespace/parens', 2,
    10551055                  'Extra space after (')
    10561056        if (search(r'\w\s+\(', function_call)
    10571057            and not search(r'#\s*define|typedef', function_call)):
    1058             error(filename, line_number, 'whitespace/parens', 4,
     1058            error(line_number, 'whitespace/parens', 4,
    10591059                  'Extra space before ( in function call')
    10601060        # If the ) is followed only by a newline or a { + newline, assume it's
    10611061        # part of a control statement (if/while/etc), and don't complain
    10621062        if search(r'[^)\s]\s+\)(?!\s*$|{\s*$)', function_call):
    1063             error(filename, line_number, 'whitespace/parens', 2,
     1063            error(line_number, 'whitespace/parens', 2,
    10641064                  'Extra space before )')
    10651065
     
    11401140        if not body_found:
    11411141            # 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,
    11431143                  'Lint failed to find start of function body.')
    11441144    elif match(r'^\}\s*$', line):  # function end
     
    12111211
    12121212            if not exception:
    1213                 error(filename, line_number, 'whitespace/blank_line', 2,
     1213                error(line_number, 'whitespace/blank_line', 2,
    12141214                      'Blank line at the start of a code block.  Is this needed?')
    12151215        # This doesn't ignore whitespace at the end of a namespace block
     
    12321232                and next_line.find('namespace') == -1
    12331233                and next_line.find('} else ') == -1):
    1234                 error(filename, line_number, 'whitespace/blank_line', 3,
     1234                error(line_number, 'whitespace/blank_line', 3,
    12351235                      'Blank line at the end of a code block.  Is this needed?')
    12361236
     
    12471247                     or (comment_position >= 2
    12481248                         and line[comment_position - 2] in string.whitespace)))):
    1249                 error(filename, line_number, 'whitespace/comments', 5,
     1249                error(line_number, 'whitespace/comments', 5,
    12501250                      'One space before end of line comments')
    12511251            # There should always be a space between the // and the comment
     
    12601260                           or search(r'^/+ ', line[commentend:]))
    12611261                if not matched:
    1262                     error(filename, line_number, 'whitespace/comments', 4,
     1262                    error(line_number, 'whitespace/comments', 4,
    12631263                          'Should have a space between // and comment')
    12641264
     
    12721272        return
    12731273    if search(r'[\w.]=[\w.]', line):
    1274         error(filename, line_number, 'whitespace/operators', 4,
     1274        error(line_number, 'whitespace/operators', 4,
    12751275              'Missing spaces around =')
    12761276
     
    12901290            matched = search(r'[^<>=!\s](<)[^<>=!\s]([^>]|->)*$', line)
    12911291    if matched:
    1292         error(filename, line_number, 'whitespace/operators', 3,
     1292        error(line_number, 'whitespace/operators', 3,
    12931293              'Missing spaces around %s' % matched.group(1))
    12941294
     
    12961296    matched = search(r'(!\s|~\s|[\s]--[\s;]|[\s]\+\+[\s;])', line)
    12971297    if matched:
    1298         error(filename, line_number, 'whitespace/operators', 4,
     1298        error(line_number, 'whitespace/operators', 4,
    12991299              'Extra space for operator %s' % matched.group(1))
    13001300
     
    13021302    matched = search(r' (if\(|for\(|foreach\(|while\(|switch\()', line)
    13031303    if matched:
    1304         error(filename, line_number, 'whitespace/parens', 5,
     1304        error(line_number, 'whitespace/parens', 5,
    13051305              'Missing space before ( in %s' % matched.group(1))
    13061306
     
    13171317                    and len(matched.group(2)) == 1 + len(matched.group(4))
    13181318                    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,
    13201320                      'Mismatching spaces inside () in %s' % matched.group(1))
    13211321        if not len(matched.group(2)) in [0, 1]:
    1322             error(filename, line_number, 'whitespace/parens', 5,
     1322            error(line_number, 'whitespace/parens', 5,
    13231323                  'Should have zero or one spaces inside ( and ) in %s' %
    13241324                  matched.group(1))
     
    13261326    # You should always have a space after a comma (either as fn arg or operator)
    13271327    if search(r',[^\s]', line):
    1328         error(filename, line_number, 'whitespace/comma', 3,
     1328        error(line_number, 'whitespace/comma', 3,
    13291329              'Missing space after ,')
    13301330
     
    13331333        matched = match(r'\s*\w+(?<!\breturn)\s+(?P<pointer_operator>\*|\&)\w+', line)
    13341334        if matched:
    1335             error(filename, line_number, 'whitespace/declaration', 3,
     1335            error(line_number, 'whitespace/declaration', 3,
    13361336                  'Declaration has space between type name and %s in %s' % (matched.group('pointer_operator'), matched.group(0).strip()))
    13371337
     
    13401340        matched = search(r'^\s*\w+\*\s+\w+', line)
    13411341        if matched:
    1342             error(filename, line_number, 'whitespace/declaration', 3,
     1342            error(line_number, 'whitespace/declaration', 3,
    13431343                  'Declaration has space between * and variable name in %s' % matched.group(0).strip())
    13441344
     
    13501350    # an easy test.
    13511351    if search(r'[^ ({]{', line):
    1352         error(filename, line_number, 'whitespace/braces', 5,
     1352        error(line_number, 'whitespace/braces', 5,
    13531353              'Missing space before {')
    13541354
    13551355    # Make sure '} else {' has spaces.
    13561356    if search(r'}else', line):
    1357         error(filename, line_number, 'whitespace/braces', 5,
     1357        error(line_number, 'whitespace/braces', 5,
    13581358              'Missing space before else')
    13591359
     
    13611361    # 'delete []' or 'new char * []'.
    13621362    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,
    13641364              'Extra space before [')
    13651365
     
    13681368    # the semicolon there.
    13691369    if search(r':\s*;\s*$', line):
    1370         error(filename, line_number, 'whitespace/semicolon', 5,
     1370        error(line_number, 'whitespace/semicolon', 5,
    13711371              'Semicolon defining empty statement. Use { } instead.')
    13721372    elif search(r'^\s*;\s*$', line):
    1373         error(filename, line_number, 'whitespace/semicolon', 5,
     1373        error(line_number, 'whitespace/semicolon', 5,
    13741374              'Line contains only semicolon. If this should be an empty statement, '
    13751375              'use { } instead.')
    13761376    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,
    13781378              'Extra space before last semicolon. If this should be an empty '
    13791379              'statement, use { } instead.')
     
    13821382          # Allow do {} while();
    13831383          and not search(r'}\s*while', line)):
    1384         error(filename, line_number, 'whitespace/semicolon', 5,
     1384        error(line_number, 'whitespace/semicolon', 5,
    13851385              'Semicolon defining empty statement for this loop. Use { } instead.')
    13861386
     
    14321432        # Don't warn about an indented namespace if we already warned about indented code.
    14331433        if not file_state.did_inside_namespace_indent_warning():
    1434             error(filename, line_number, 'whitespace/indent', 4,
     1434            error(line_number, 'whitespace/indent', 4,
    14351435                  'namespace should never be indented.')
    14361436        return
     
    14461446                if not match(r'\S', current_line) and not file_state.did_inside_namespace_indent_warning():
    14471447                    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,
    14491449                          'Code inside a namespace should not be indented.')
    14501450            if in_preprocessor_directive or (current_line.strip()[0] == '#'): # This takes care of preprocessor directive syntax.
     
    14791479
    14801480    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,
    14821482          "Use 'using namespace std;' instead of 'using std::%s;'." % method_name)
    14831483
     
    15051505    max_min_macro = max_min_macros_search.group('max_min_macro')
    15061506    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,
    15081508          'Use std::%s() or std::%s<type>() instead of the %s() macro.'
    15091509          % (max_min_macro_lower, max_min_macro_lower, max_min_macro))
     
    15601560        elif match(r'(default|case\s+.*)\s*:([^:].*)?$', remaining_line):
    15611561            if current_indentation != switch_indentation:
    1562                 error(filename, line_number + line_offset, 'whitespace/indent', 4,
     1562                error(line_number + line_offset, 'whitespace/indent', 4,
    15631563                      'A case label should not be indented, but line up with its switch statement.')
    15641564                # Don't throw an error for multiple badly indented labels,
     
    15711571        # the switch statement plus one more level of indentation.
    15721572        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,
    15741574                  'Non-label code inside switch statements should be indented.')
    15751575            # Don't throw an error for multiple badly indented statements,
     
    16061606             or search(r'\b(if|for|foreach|while|switch|else)\b', previous_line))
    16071607            and previous_line.find('#') < 0):
    1608             error(filename, line_number, 'whitespace/braces', 4,
     1608            error(line_number, 'whitespace/braces', 4,
    16091609                  'This { should be at the end of the previous line')
    16101610    elif (search(r'\)\s*(const\s*)?{\s*$', line)
     
    16121612          and not search(r'\b(if|for|foreach|while|switch)\b', line)
    16131613          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,
    16151615              'Place brace on its own line for function definitions.')
    16161616
     
    16211621        if (previous_line.find('{') > 0
    16221622            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,
    16241624                  'One line control clauses should not use braces.')
    16251625
     
    16281628        previous_line = get_previous_non_blank_line(clean_lines, line_number)[0]
    16291629        if match(r'\s*}\s*$', previous_line):
    1630             error(filename, line_number, 'whitespace/newline', 4,
     1630            error(line_number, 'whitespace/newline', 4,
    16311631                  'An else should appear on the same line as the preceding }')
    16321632
    16331633    # Likewise, an else should never have the else clause on the same line
    16341634    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,
    16361636              'Else clause should never be on same line as else (use 2 lines)')
    16371637
    16381638    # In the same way, a do/while should never be on one line
    16391639    if match(r'\s*do [^\s{]', line):
    1640         error(filename, line_number, 'whitespace/newline', 4,
     1640        error(line_number, 'whitespace/newline', 4,
    16411641              'do/while clauses should not be on a single line')
    16421642
     
    16541654        and line.count('{') == line.count('}')
    16551655        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,
    16571657              "You don't need a ; after a }")
    16581658
     
    17371737        if match(r'if\s*\(', remaining_line):
    17381738            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,
    17401740                      'An else statement can be removed when the prior "if" '
    17411741                      'concludes with a return, break, continue or goto statement.')
    17421742            else:
    1743                 error(filename, line_number + line_offset, 'readability/control_flow', 4,
     1743                error(line_number + line_offset, 'readability/control_flow', 4,
    17441744                      'An else if statement should be written as an if statement '
    17451745                      'when the prior "if" concludes with a return, break, '
     
    18091809    for operator in ['==', '!=', '>=', '>', '<=', '<']:
    18101810        if replaceable_check(operator, current_macro, line):
    1811             error(filename, line_number, 'readability/check', 2,
     1811            error(line_number, 'readability/check', 2,
    18121812                  'Consider using %s instead of %s(a %s b)' % (
    18131813                      _CHECK_REPLACEMENT[current_macro][operator],
     
    18221822    # Include NULL here so that users don't have to convert NULL to 0 first and then get this error.
    18231823    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,
    18251825              'Tests for true/false, null/non-null, and zero/non-zero should all be done without equality comparisons.')
    18261826
     
    18381838
    18391839    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.')
    18411841        return
    18421842
     
    18461846    # NULLs occurring in strings.
    18471847    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.')
    18491849
    18501850def get_line_width(line):
     
    18901890
    18911891    if line.find('\t') != -1:
    1892         error(filename, line_number, 'whitespace/tab', 1,
     1892        error(line_number, 'whitespace/tab', 1,
    18931893              'Tab found; better to use spaces')
    18941894
     
    19101910        initial_spaces += 1
    19111911    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,
    19131913              'Line ends in whitespace.  Consider deleting these extra spaces.')
    19141914    # There are certain situations we allow one space, notably for labels
    19151915    elif ((initial_spaces >= 1 and initial_spaces <= 3)
    19161916          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,
    19181918              'Weird number of spaces at line-start.  '
    19191919              'Are you using a 4-space indent?')
     
    19271927            # because goto labels can in fact occur at the start of the line.
    19281928            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,
    19301930                      'Labels should always be indented at least one space.  '
    19311931                      'If this is a member-initializer list in a constructor, '
     
    19421942                 and cleansed_line.find('break;') != -1)
    19431943        and not cleansed_line.startswith('#define ')):
    1944         error(filename, line_number, 'whitespace/newline', 4,
     1944        error(line_number, 'whitespace/newline', 4,
    19451945              'More than one command on the same line')
    19461946
    19471947    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,
    19491949              'Boolean expressions that span multiple lines should have their '
    19501950              'operators on the left side of the line instead of the right side.')
     
    21162116        # Many unit tests use cout, so we exempt them.
    21172117        if not _is_test_filename(filename):
    2118             error(filename, line_number, 'readability/streams', 3,
     2118            error(line_number, 'readability/streams', 3,
    21192119                  'Streams are highly discouraged.')
    21202120
    21212121    # Look for specific includes to fix.
    21222122    if include.startswith('wtf/') and not is_system:
    2123         error(filename, line_number, 'build/include', 4,
     2123        error(line_number, 'build/include', 4,
    21242124              'wtf includes should be <wtf/file.h> instead of "wtf/file.h".')
    21252125
    21262126    duplicate_header = include in include_state
    21272127    if duplicate_header:
    2128         error(filename, line_number, 'build/include', 4,
     2128        error(line_number, 'build/include', 4,
    21292129              '"%s" already included at %s:%s' %
    21302130              (include, filename, include_state[include]))
     
    21502150         next_line = clean_lines.raw_lines[line_number + 1]
    21512151         if not is_blank_line(next_line):
    2152             error(filename, line_number, 'build/include_order', 4,
     2152            error(line_number, 'build/include_order', 4,
    21532153                  'You should add a blank line after implementation file\'s own header.')
    21542154
     
    21672167            previous_header_type = include_state.header_types[previous_line_number]
    21682168            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,
    21702170                      'Alphabetical sorting problem.')
    21712171
    21722172    if error_message:
    21732173        if filename.endswith('.h'):
    2174             error(filename, line_number, 'build/include_order', 4,
     2174            error(line_number, 'build/include_order', 4,
    21752175                  '%s Should be: alphabetically sorted.' %
    21762176                  error_message)
    21772177        else:
    2178             error(filename, line_number, 'build/include_order', 4,
     2178            error(line_number, 'build/include_order', 4,
    21792179                  '%s Should be: config.h, primary header, blank line, and then alphabetically sorted.' %
    21802180                  error_message)
     
    22202220        # virtually indistinguishable from int(x) casts.
    22212221        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,
    22232223                  'Using deprecated casting style.  '
    22242224                  'Use static_cast<%s>(...) instead' %
     
    22382238    if search(
    22392239        r'(&\([^)]+\)[\w(])|(&(static|dynamic|reinterpret)_cast\b)', line):
    2240         error(filename, line_number, 'runtime/casting', 4,
     2240        error(line_number, 'runtime/casting', 4,
    22412241              ('Are you taking an address of a cast?  '
    22422242               'This is dangerous: could be a temp var.  '
     
    22542254    if matched and not match(r'\s*(<.*>)?(::[a-zA-Z0-9_]+)?\s*\(([^"]|$)',
    22552255                             matched.group(3)):
    2256         error(filename, line_number, 'runtime/string', 4,
     2256        error(line_number, 'runtime/string', 4,
    22572257              'For a static/global string constant, use a C style string instead: '
    22582258              '"%schar %s[]".' %
     
    22612261    # Check that we're not using RTTI outside of testing code.
    22622262    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,
    22642264              'Do not use dynamic_cast<>.  If you need to cast within a class '
    22652265              "hierarchy, use static_cast<> to upcast.  Google doesn't support "
     
    22672267
    22682268    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,
    22702270              'You seem to be initializing a member variable with itself.')
    22712271
     
    22802280    if search(r'\bshort port\b', line):
    22812281        if not search(r'\bunsigned short port\b', line):
    2282             error(filename, line_number, 'runtime/int', 4,
     2282            error(line_number, 'runtime/int', 4,
    22832283                  'Use "unsigned short" for ports, not "short"')
    22842284
     
    22862286    matched = search(r'snprintf\s*\(([^,]*),\s*([0-9]*)\s*,', line)
    22872287    if matched:
    2288         error(filename, line_number, 'runtime/printf', 3,
     2288        error(line_number, 'runtime/printf', 3,
    22892289              'If you can, use sizeof(%s) instead of %s as the 2nd arg '
    22902290              'to snprintf.' % (matched.group(1), matched.group(2)))
     
    22922292    # Check if some verboten C functions are being used.
    22932293    if search(r'\bsprintf\b', line):
    2294         error(filename, line_number, 'runtime/printf', 5,
     2294        error(line_number, 'runtime/printf', 5,
    22952295              'Never use sprintf.  Use snprintf instead.')
    22962296    matched = search(r'\b(strcpy|strcat)\b', line)
    22972297    if matched:
    2298         error(filename, line_number, 'runtime/printf', 4,
     2298        error(line_number, 'runtime/printf', 4,
    22992299              'Almost always, snprintf is better than %s' % matched.group(1))
    23002300
    23012301    if search(r'\bsscanf\b', line):
    2302         error(filename, line_number, 'runtime/printf', 1,
     2302        error(line_number, 'runtime/printf', 1,
    23032303              'sscanf can be ok, but is slow and can overflow buffers.')
    23042304
     
    23062306    # } if (a == b) {
    23072307    if search(r'\}\s*if\s*\(', line):
    2308         error(filename, line_number, 'readability/braces', 4,
     2308        error(line_number, 'readability/braces', 4,
    23092309              'Did you mean "else if"? If not, start a new line for "if".')
    23102310
     
    23142314    matched = re.search(r'\b((?:string)?printf)\s*\(([\w.\->()]+)\)', line, re.I)
    23152315    if matched:
    2316         error(filename, line_number, 'runtime/printf', 4,
     2316        error(line_number, 'runtime/printf', 4,
    23172317              'Potential format string bug. Do %s("%%s", %s) instead.'
    23182318              % (matched.group(1), matched.group(2)))
     
    23212321    matched = search(r'memset\s*\(([^,]*),\s*([^,]*),\s*0\s*\)', line)
    23222322    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,
    23242324              'Did you mean "memset(%s, 0, %s)"?'
    23252325              % (matched.group(1), matched.group(2)))
     
    23682368            break
    23692369        if not is_const:
    2370             error(filename, line_number, 'runtime/arrays', 1,
     2370            error(line_number, 'runtime/arrays', 1,
    23712371                  'Do not use variable-length arrays.  Use an appropriately named '
    23722372                  "('k' followed by CamelCase) compile-time constant for the size.")
     
    23782378        and search(r'\bnamespace\s*{', line)
    23792379        and line[-1] != '\\'):
    2380         error(filename, line_number, 'build/namespaces', 4,
     2380        error(line_number, 'build/namespaces', 4,
    23812381              'Do not use unnamed namespaces in header files.  See '
    23822382              'http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
     
    24772477                and not modified_identifier.find('::qt_') >= 0
    24782478                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.")
    24802480
    24812481        # There can be only one declaration in non-for-control statements.
     
    25152515    sizeof_match = match(r'.*sizeof\s*$', line[0:matched.start(1) - 1])
    25162516    if sizeof_match:
    2517         error(filename, line_number, 'runtime/sizeof', 1,
     2517        error(line_number, 'runtime/sizeof', 1,
    25182518              'Using sizeof(type).  Use sizeof(varname) instead if possible')
    25192519        return
     
    25372537            or function_match.group(3) == ';'
    25382538            or raw_line.find('/*') < 0):
    2539             error(filename, line_number, 'readability/function', 3,
     2539            error(line_number, 'readability/function', 3,
    25402540                  'All parameters should be named in a function')
    25412541        return
    25422542
    25432543    # 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,
    25452545          'Using C-style cast.  Use %s<%s>(...) instead' %
    25462546          (cast_type, matched.group(1)))
     
    27822782                continue
    27832783        if required_header_unstripped.strip('<>"') not in include_state:
    2784             error(filename, required[required_header_unstripped][0],
     2784            error(required[required_header_unstripped][0],
    27852785                  'build/include_what_you_use', 4,
    27862786                  'Add #include ' + required_header_unstripped + ' for ' + template)
  • trunk/WebKitTools/Scripts/webkitpy/style/cpp_style_unittest.py

    r53675 r53841  
    6363        self._errors = []
    6464
    65     def __call__(self, unused_filename, unused_linenum,
    66                  category, confidence, message):
     65    def __call__(self, unused_linenum, category, confidence, message):
    6766        self._assert_fn(category in self._all_style_categories,
    6867                        'Message "%s" has category "%s",'
  • trunk/WebKitTools/Scripts/webkitpy/style/text_style.py

    r53675 r53841  
    4545        for line_number, line in enumerate(lines):
    4646            if "\t" in line:
    47                 self.handle_style_error(self.file_path, line_number,
     47                self.handle_style_error(line_number,
    4848                                        "whitespace/tab", 5,
    4949                                        "Line contains tab character.")
  • trunk/WebKitTools/Scripts/webkitpy/style/text_style_unittest.py

    r53675 r53841  
    4242        self.had_error = False
    4343
    44         def error_for_test(filename, line_number, category, confidence, message):
     44        def error_for_test(line_number, category, confidence, message):
    4545            """Records if an error occurs."""
    4646            self.had_error = True
     
    5353        self.had_error = False
    5454
    55         def error_for_test(filename, line_number, category, confidence, message):
     55        def error_for_test(line_number, category, confidence, message):
    5656            """Checks if the expected error occurs."""
    5757            self.assertEquals(expected_line_number, line_number)
Note: See TracChangeset for help on using the changeset viewer.