示例#1
0
def check_webkit_style_configuration(options):
    """Return a StyleProcessorConfiguration instance for check-webkit-style.

    Args:
      options: A CommandOptionValues instance.

    """
    filter_configuration = FilterConfiguration(
                               base_rules=_BASE_FILTER_RULES,
                               path_specific=_PATH_RULES_SPECIFIER,
                               user_rules=options.filter_rules)

    return StyleProcessorConfiguration(filter_configuration=filter_configuration,
               max_reports_per_category=_MAX_REPORTS_PER_CATEGORY,
               min_confidence=options.min_confidence,
               output_format=options.output_format,
               commit_queue=options.commit_queue)
示例#2
0
    def test_process(self):
        configuration = StyleProcessorConfiguration(
            filter_configuration=FilterConfiguration(),
            max_reports_per_category={},
            min_confidence=3,
            output_format="vs7",
            commit_queue=False)
        processor = StyleProcessor(configuration)

        processor.process(lines=['line1', 'Line with tab:\t'],
                          file_path='foo.txt')

        self.assertEqual(processor.error_count, 1)
        expected_messages = [
            'ERROR: foo.txt(2):  Line contains tab character.  '
            '[whitespace/tab] [5]\n'
        ]
        self.assertLog(expected_messages)
示例#3
0
 def _config(self, base_rules, path_specific, user_rules):
     """Return a FilterConfiguration instance."""
     return FilterConfiguration(base_rules=base_rules,
                                path_specific=path_specific,
                                user_rules=user_rules)
示例#4
0
    def test_path_rules_specifier(self):
        all_categories = self._all_categories()
        for (sub_paths, path_rules) in PATH_RULES_SPECIFIER:
            validate_filter_rules(path_rules, self._all_categories())

        config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)

        def assertCheck(path, category):
            """Assert that the given category should be checked."""
            message = ('Should check category "%s" for path "%s".'
                       % (category, path))
            self.assertTrue(config.should_check(category, path))

        def assertNoCheck(path, category):
            """Assert that the given category should not be checked."""
            message = ('Should not check category "%s" for path "%s".'
                       % (category, path))
            self.assertFalse(config.should_check(category, path), message)

        assertCheck("random_path.cpp",
                    "build/include")
        assertNoCheck(os.path.join('Tools', 'DumpRenderTree', 'TestNetscapePlugIn', 'main.cpp'),
                      "build/include")
        assertNoCheck(os.path.join('Tools', 'DumpRenderTree', 'TestNetscapePlugIn', 'main.cpp'),
                      "readability/naming")
        assertCheck(os.path.join('Tools', 'TestWebKitAPI', 'Tests', 'WTF', 'RefLogger.cpp'),
                      "build/include")
        assertNoCheck(os.path.join('Tools', 'TestWebKitAPI', 'Tests', 'mac', 'WillSendSubmitEvent.mm'),
                      "readability/naming")
        assertCheck("random_path.cpp",
                    "readability/naming")
        assertNoCheck(os.path.join('Source', 'WebCore', 'css', 'CSSParser.cpp'),
                      "readability/naming")

        assertNoCheck(os.path.join('Source', 'WebCore', 'ForwardingHeaders', 'debugger', 'Debugger.h'),
                      "build/header_guard")

        assertNoCheck(os.path.join('Source', 'WebCore', 'platform', 'graphics', 'gstreamer', 'VideoSinkGStreamer.cpp'),
                      "readability/naming")

        # Third-party Python code: webkitpy/thirdparty
        path = os.path.join('Tools', 'Scripts', 'webkitpy', 'thirdparty', 'mock.py')
        assertNoCheck(path, "build/include")
        assertNoCheck(path, "pep8/E401")  # A random pep8 category.
        assertCheck(path, "pep8/W191")
        assertCheck(path, "pep8/W291")
        assertCheck(path, "whitespace/carriage_return")

        # Test if the exception for GDBInterface.cpp is in place.
        assertNoCheck(os.path.join('Source', 'JavaScriptCore', 'jit', 'GDBInterface.cpp'),
                      "readability/naming")

        # Javascript keywords.
        assertCheck(os.path.join('Source', 'JavaScriptCore', 'parser', 'Keywords.table'), "whitespace/carriage_return")

        # Test if the exception for DataDetectorsCoreSPI.h is in place.
        assertNoCheck(os.path.join('Source', 'WebCore', 'PAL', 'pal', 'spi', 'cocoa', 'DataDetectorsCoreSPI.h'),
                      "runtime/enum_bitfields")

        # Test if the exception for PassKitSPI.h is in place.
        assertNoCheck(os.path.join('Source', 'WebCore', 'PAL', 'pal', 'spi', 'cocoa', 'PassKitSPI.h'),
                      "build/include")

        # Test if the exception for pal/spi is in place.
        assertNoCheck(os.path.join('Source', 'WebCore', 'PAL', 'pal', 'spi'),
                      "readability/naming/underscores")