Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
2009-12-16 Kent Tamura <tkent@chromium.org>
Reviewed by David Levin. check-webkit-style supports for TAB check against text files. https://bugs.webkit.org/show_bug.cgi?id=32538 * Scripts/check-webkit-style: Move process_patch() to style.py. * Scripts/modules/cpp_style.py: Add can_handle(). * Scripts/modules/cpp_style_unittest.py: Add tests for can_handle(). * Scripts/modules/style.py: Added. This is a front-end of cpp_style and text_style. It dispatches files to an appropriate linter. * Scripts/modules/text_style.py: Added. This is a linter module for generic text files. It supports only for TAB checking at this moment. * Scripts/modules/text_style_unittest.py: Added. Tests for text_style.py. * Scripts/run-webkit-unittests: Add text_style_unittest. Canonical link: https://commits.webkit.org/43656@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@52232 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
1 parent
5aaa765
commit 8c9a317
Showing
8 changed files
with
349 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Copyright (C) 2009 Google Inc. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are | ||
# met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above | ||
# copyright notice, this list of conditions and the following disclaimer | ||
# in the documentation and/or other materials provided with the | ||
# distribution. | ||
# * Neither the name of Google Inc. nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
"""Front end of some style-checker modules.""" | ||
|
||
# FIXME: Move more code from cpp_style to here. | ||
# check-webkit-style should not refer cpp_style directly. | ||
|
||
import os.path | ||
|
||
import modules.cpp_style as cpp_style | ||
import modules.text_style as text_style | ||
from modules.diff_parser import DiffParser | ||
|
||
|
||
def use_webkit_styles(): | ||
"""Configures this module for WebKit style.""" | ||
cpp_style._DEFAULT_FILTER_RULES = cpp_style._WEBKIT_FILTER_RULES | ||
|
||
|
||
def parse_arguments(args, additional_flags=[], display_help=False): | ||
"""Parses the command line arguments. | ||
See cpp_style.parse_arguments() for details. | ||
""" | ||
return cpp_style.parse_arguments(args, additional_flags, display_help) | ||
|
||
|
||
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 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) | ||
|
||
|
||
def error_count(): | ||
"""Returns the total error count.""" | ||
return cpp_style.error_count() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright (C) 2009 Google Inc. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are | ||
# met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above | ||
# copyright notice, this list of conditions and the following disclaimer | ||
# in the documentation and/or other materials provided with the | ||
# distribution. | ||
# * Neither the name of Google Inc. nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
"""Does WebKit-lint on text files. | ||
This module shares error count, filter setting, output setting, etc. with cpp_style. | ||
""" | ||
|
||
import codecs | ||
import os.path | ||
import sys | ||
|
||
import cpp_style | ||
|
||
|
||
def process_file_data(filename, lines, error): | ||
"""Performs lint check for text on the specified lines. | ||
It reports errors to the given error function. | ||
""" | ||
lines = (['// adjust line numbers to make the first line 1.'] + lines) | ||
|
||
# FIXME: share with cpp_style.check_style() | ||
for line_number, line in enumerate(lines): | ||
if '\t' in line: | ||
error(filename, line_number, 'whitespace/tab', 5, 'Line contains tab character.') | ||
|
||
|
||
def process_file(filename, error=cpp_style.error): | ||
"""Performs lint check for text on a single file.""" | ||
if (not can_handle(filename)): | ||
sys.stderr.write('Ignoring %s; not a supported file\n' % filename) | ||
return | ||
|
||
# FIXME: share code with cpp_style.process_file(). | ||
try: | ||
# Do not support for filename='-'. cpp_style handles it. | ||
lines = codecs.open(filename, 'r', 'utf8', 'replace').read().split('\n') | ||
except IOError: | ||
sys.stderr.write("Skipping input '%s': Can't open for reading\n" % filename) | ||
return | ||
process_file_data(filename, lines, error) | ||
|
||
|
||
def can_handle(filename): | ||
"""Checks if this module supports the specified file type. | ||
Args: | ||
filename: A filename. It may contain directory names. | ||
""" | ||
return ("ChangeLog" in filename | ||
or "WebKitTools/Scripts/" in filename | ||
or os.path.splitext(filename)[1] in ('.css', '.html', '.idl', '.js', '.mm', '.php', '.pm', '.py', '.txt')) and not "LayoutTests/" in filename |
Oops, something went wrong.