Beispiel #1
0
def process_patch(patch_string):
    """Does lint on a single patch.

    Args:
      patch_string: A string of a patch.
    """
    patch = DiffParser(patch_string.splitlines())
    for filename, diff in patch.files.iteritems():
        file_extension = os.path.splitext(filename)[1]
        line_numbers = set()

        def error_for_patch(filename, line_number, category, confidence,
                            message):
            """Wrapper function of cpp_style.error for patches.

            This function outputs errors only if the line number
            corresponds to lines which are modified or added.
            """
            if not line_numbers:
                for line in diff.lines:
                    # When deleted line is not set, it means that
                    # the line is newly added.
                    if not line[0]:
                        line_numbers.add(line[1])

            if line_number in line_numbers:
                cpp_style.error(filename, line_number, category, confidence,
                                message)

        if cpp_style.can_handle(filename):
            cpp_style.process_file(filename, error=error_for_patch)
        elif text_style.can_handle(filename):
            text_style.process_file(filename, error=error_for_patch)
Beispiel #2
0
def process_patch(patch_string):
    """Does lint on a single patch.

    Args:
      patch_string: A string of a patch.
    """
    patch = DiffParser(patch_string.splitlines())
    for filename, diff in patch.files.iteritems():
        file_extension = os.path.splitext(filename)[1]
        line_numbers = set()

        def error_for_patch(filename, line_number, category, confidence, message):
            """Wrapper function of cpp_style.error for patches.

            This function outputs errors only if the line number
            corresponds to lines which are modified or added.
            """
            if not line_numbers:
                for line in diff.lines:
                    # When deleted line is not set, it means that
                    # the line is newly added.
                    if not line[0]:
                        line_numbers.add(line[1])

            if line_number in line_numbers:
                cpp_style.error(filename, line_number, category, confidence, message)

        if cpp_style.can_handle(filename):
            cpp_style.process_file(filename, error=error_for_patch)
        elif text_style.can_handle(filename):
            text_style.process_file(filename, error=error_for_patch)
Beispiel #3
0
def process_file(filename):
    """Checks style for the specified file.

    If the specified filename is '-', applies cpp_style to the standard input.
    """
    if cpp_style.can_handle(filename) or filename == '-':
        cpp_style.process_file(filename)
    elif text_style.can_handle(filename):
        text_style.process_file(filename)
Beispiel #4
0
def process_file(filename):
    """Checks style for the specified file.

    If the specified filename is '-', applies cpp_style to the standard input.
    """
    if cpp_style.can_handle(filename) or filename == '-':
        cpp_style.process_file(filename)
    elif text_style.can_handle(filename):
        text_style.process_file(filename)
    def test_can_handle(self):
        """Tests for text_style.can_handle()."""
        self.assert_(not text_style.can_handle(''))
        self.assert_(not text_style.can_handle('-'))
        self.assert_(text_style.can_handle('ChangeLog'))
        self.assert_(text_style.can_handle('WebCore/ChangeLog'))
        self.assert_(text_style.can_handle('FooChangeLog.bak'))
        self.assert_(text_style.can_handle('WebKitTools/Scripts/check-webkit=style'))
        self.assert_(text_style.can_handle('WebKitTools/Scripts/modules/text_style.py'))
        self.assert_(not text_style.can_handle('WebKitTools/Scripts'))

        self.assert_(text_style.can_handle('foo.css'))
        self.assert_(text_style.can_handle('foo.html'))
        self.assert_(text_style.can_handle('foo.idl'))
        self.assert_(text_style.can_handle('foo.js'))
        self.assert_(text_style.can_handle('WebCore/inspector/front-end/inspector.js'))
        self.assert_(text_style.can_handle('foo.mm'))
        self.assert_(text_style.can_handle('foo.php'))
        self.assert_(text_style.can_handle('foo.pm'))
        self.assert_(text_style.can_handle('foo.py'))
        self.assert_(text_style.can_handle('foo.txt'))
        self.assert_(not text_style.can_handle('foo.c'))
        self.assert_(not text_style.can_handle('foo.c'))
        self.assert_(not text_style.can_handle('foo.c'))
        self.assert_(not text_style.can_handle('foo.png'))
        self.assert_(not text_style.can_handle('foo.c/bar.png'))
        self.assert_(not text_style.can_handle('WebKit/English.lproj/Localizable.strings'))
        self.assert_(not text_style.can_handle('Makefile'))
        self.assert_(not text_style.can_handle('WebCore/Android.mk'))
        self.assert_(not text_style.can_handle('LayoutTests/inspector/console-tests.js'))
    def test_can_handle(self):
        """Tests for text_style.can_handle()."""
        self.assert_(not text_style.can_handle(''))
        self.assert_(not text_style.can_handle('-'))
        self.assert_(text_style.can_handle('ChangeLog'))
        self.assert_(text_style.can_handle('WebCore/ChangeLog'))
        self.assert_(text_style.can_handle('FooChangeLog.bak'))
        self.assert_(
            text_style.can_handle('WebKitTools/Scripts/check-webkit=style'))
        self.assert_(
            text_style.can_handle('WebKitTools/Scripts/modules/text_style.py'))
        self.assert_(not text_style.can_handle('WebKitTools/Scripts'))

        self.assert_(text_style.can_handle('foo.css'))
        self.assert_(text_style.can_handle('foo.html'))
        self.assert_(text_style.can_handle('foo.idl'))
        self.assert_(text_style.can_handle('foo.js'))
        self.assert_(
            text_style.can_handle('WebCore/inspector/front-end/inspector.js'))
        self.assert_(text_style.can_handle('foo.mm'))
        self.assert_(text_style.can_handle('foo.php'))
        self.assert_(text_style.can_handle('foo.pm'))
        self.assert_(text_style.can_handle('foo.py'))
        self.assert_(text_style.can_handle('foo.txt'))
        self.assert_(not text_style.can_handle('foo.c'))
        self.assert_(not text_style.can_handle('foo.c'))
        self.assert_(not text_style.can_handle('foo.c'))
        self.assert_(not text_style.can_handle('foo.png'))
        self.assert_(not text_style.can_handle('foo.c/bar.png'))
        self.assert_(not text_style.can_handle(
            'WebKit/English.lproj/Localizable.strings'))
        self.assert_(not text_style.can_handle('Makefile'))
        self.assert_(not text_style.can_handle('WebCore/Android.mk'))
        self.assert_(not text_style.can_handle(
            'LayoutTests/inspector/console-tests.js'))