Changeset 51619 in webkit


Ignore:
Timestamp:
Dec 2, 2009 9:08:59 PM (14 years ago)
Author:
eric@webkit.org
Message:

2009-12-02 David Levin <levin@chromium.org>

Reviewed by Adam Barth.

check-webkit-style is too noisy about namespace indenting issues.
https://bugs.webkit.org/show_bug.cgi?id=32096

  • Scripts/modules/cpp_style.py: Added a _FileState object to be able to track file level information. In this case, it simply tracks whether the error has already been given, so that it isn't done again.
  • Scripts/modules/cpp_style_unittest.py: Modified test cases to pass in the _FileState object and fix a test that expected to see the namespace error twice (now it only occurs once). No new tests because existing tests cover the change in functionality.
Location:
trunk/WebKitTools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r51618 r51619  
     12009-12-02  David Levin  <levin@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        check-webkit-style is too noisy about namespace indenting issues.
     6        https://bugs.webkit.org/show_bug.cgi?id=32096
     7
     8        * Scripts/modules/cpp_style.py:
     9        Added a _FileState object to be able to track file level information. In this
     10        case, it simply tracks whether the error has already been given, so that it isn't
     11        done again.
     12        * Scripts/modules/cpp_style_unittest.py:
     13        Modified test cases to pass in the _FileState object and fix a test that expected
     14        to see the namespace error twice (now it only occurs once). No new tests because
     15        existing tests cover the change in functionality.
     16
    1172009-12-01  Kevin Ollivier  <kevino@theolliviers.com>
    218
  • trunk/WebKitTools/Scripts/modules/cpp_style.py

    r51570 r51619  
    11201120
    11211121
     1122class _FileState(object):
     1123    def __init__(self):
     1124        self._did_inside_namespace_indent_warning = False
     1125
     1126    def set_did_inside_namespace_indent_warning(self):
     1127        self._did_inside_namespace_indent_warning = True
     1128
     1129    def did_inside_namespace_indent_warning(self):
     1130        return self._did_inside_namespace_indent_warning
     1131
    11221132def check_for_non_standard_constructs(filename, clean_lines, line_number,
    11231133                                      class_state, error):
     
    16761686
    16771687
    1678 def check_namespace_indentation(filename, clean_lines, line_number, file_extension, error):
     1688def check_namespace_indentation(filename, clean_lines, line_number, file_extension, file_state, error):
    16791689    """Looks for indentation errors inside of namespaces.
    16801690
     
    16841694      line_number: The number of the line to check.
    16851695      file_extension: The extension (dot not included) of the file.
     1696      file_state: A _FileState instance which maintains information about
     1697                  the state of things in the file.
    16861698      error: The function to call with any errors found.
    16871699    """
     
    16951707    current_indentation_level = len(namespace_match.group('namespace_indentation'))
    16961708    if current_indentation_level > 0:
    1697         error(filename, line_number, 'whitespace/indent', 4,
    1698               'namespace should never be indented.')
     1709        # Don't warn about an indented namespace if we already warned about indented code.
     1710        if not file_state.did_inside_namespace_indent_warning():
     1711            error(filename, line_number, 'whitespace/indent', 4,
     1712                  'namespace should never be indented.')
    16991713        return
    17001714    looking_for_semicolon = False;
     
    17071721        if not current_indentation_level:
    17081722            if not (in_preprocessor_directive or looking_for_semicolon):
    1709                 if not match(r'\S', current_line):
     1723                if not match(r'\S', current_line) and not file_state.did_inside_namespace_indent_warning():
     1724                    file_state.set_did_inside_namespace_indent_warning()
    17101725                    error(filename, line_number + line_offset, 'whitespace/indent', 4,
    17111726                          'Code inside a namespace should not be indented.')
     
    21252140
    21262141
    2127 def check_style(filename, clean_lines, line_number, file_extension, error):
     2142def check_style(filename, clean_lines, line_number, file_extension, file_state, error):
    21282143    """Checks rules from the 'C++ style rules' section of cppguide.html.
    21292144
     
    21372152      line_number: The number of the line to check.
    21382153      file_extension: The extension (without the dot) of the filename.
     2154      file_state: A _FileState instance which maintains information about
     2155                  the state of things in the file.
    21392156      error: The function to call with any errors found.
    21402157    """
     
    22042221
    22052222    # Some more style checks
    2206     check_namespace_indentation(filename, clean_lines, line_number, file_extension, error)
     2223    check_namespace_indentation(filename, clean_lines, line_number, file_extension, file_state, error)
    22072224    check_using_std(filename, clean_lines, line_number, error)
    22082225    check_max_min_macros(filename, clean_lines, line_number, error)
     
    29152932def process_line(filename, file_extension,
    29162933                 clean_lines, line, include_state, function_state,
    2917                  class_state, error):
     2934                 class_state, file_state, error):
    29182935    """Processes a single line in the file.
    29192936
     
    29282945      class_state: A _ClassState instance which maintains information about
    29292946                   the current stack of nested class declarations being parsed.
     2947      file_state: A _FileState instance which maintains information about
     2948                  the state of things in the file.
    29302949      error: A callable to which errors are reported, which takes 4 arguments:
    29312950             filename, line number, error level, and message
     
    29372956        return
    29382957    check_for_multiline_comments_and_strings(filename, clean_lines, line, error)
    2939     check_style(filename, clean_lines, line, file_extension, error)
     2958    check_style(filename, clean_lines, line, file_extension, file_state, error)
    29402959    check_language(filename, clean_lines, line, file_extension, include_state,
    29412960                   error)
     
    29622981    function_state = _FunctionState()
    29632982    class_state = _ClassState()
     2983    file_state = _FileState()
    29642984
    29652985    check_for_copyright(filename, lines, error)
     
    29722992    for line in xrange(clean_lines.num_lines()):
    29732993        process_line(filename, file_extension, clean_lines, line,
    2974                      include_state, function_state, class_state, error)
     2994                     include_state, function_state, class_state, file_state, error)
    29752995    class_state.check_finished(filename, error)
    29762996
  • trunk/WebKitTools/Scripts/modules/cpp_style_unittest.py

    r51570 r51619  
    121121        ext = file_name[file_name.rfind('.') + 1:]
    122122        class_state = cpp_style._ClassState()
     123        file_state = cpp_style._FileState()
    123124        cpp_style.process_line(file_name, ext, clean_lines, 0,
    124125                               include_state, function_state,
    125                                class_state, error_collector)
     126                               class_state, file_state, error_collector)
    126127        # Single-line lint tests are allowed to fail the 'unlintable function'
    127128        # check.
     
    138139        ext = file_name[file_name.rfind('.') + 1:]
    139140        class_state = cpp_style._ClassState()
     141        file_state = cpp_style._FileState()
    140142        for i in xrange(lines.num_lines()):
    141             cpp_style.check_style(file_name, lines, i, ext, error_collector)
     143            cpp_style.check_style(file_name, lines, i, ext, file_state, error_collector)
    142144            cpp_style.check_for_non_standard_constructs(file_name, lines, i, class_state,
    143145                                                        error_collector)
     
    28352837            '};\n'
    28362838            '}',
    2837             ['Code inside a namespace should not be indented.  [whitespace/indent] [4]', 'namespace should never be indented.  [whitespace/indent] [4]'],
     2839            'Code inside a namespace should not be indented.  [whitespace/indent] [4]',
     2840            'foo.h')
     2841        self.assert_multi_line_lint(
     2842            'namespace OuterNamespace {\n'
     2843            '    class Document {\n'
     2844            '    namespace InnerNamespace {\n'
     2845            '};\n'
     2846            '};\n'
     2847            '}',
     2848            'Code inside a namespace should not be indented.  [whitespace/indent] [4]',
    28382849            'foo.h')
    28392850        self.assert_multi_line_lint(
Note: See TracChangeset for help on using the changeset viewer.