aboutsummaryrefslogtreecommitdiff
path: root/tools/closure_linter-2.3.4/closure_linter/common
diff options
context:
space:
mode:
Diffstat (limited to 'tools/closure_linter-2.3.4/closure_linter/common')
-rwxr-xr-xtools/closure_linter-2.3.4/closure_linter/common/__init__.py1
-rwxr-xr-xtools/closure_linter-2.3.4/closure_linter/common/error.py65
-rwxr-xr-xtools/closure_linter-2.3.4/closure_linter/common/erroraccumulator.py46
-rwxr-xr-xtools/closure_linter-2.3.4/closure_linter/common/errorhandler.py61
-rwxr-xr-xtools/closure_linter-2.3.4/closure_linter/common/errorprinter.py203
-rwxr-xr-xtools/closure_linter-2.3.4/closure_linter/common/filetestcase.py105
-rwxr-xr-xtools/closure_linter-2.3.4/closure_linter/common/htmlutil.py170
-rwxr-xr-xtools/closure_linter-2.3.4/closure_linter/common/lintrunner.py39
-rwxr-xr-xtools/closure_linter-2.3.4/closure_linter/common/matcher.py60
-rwxr-xr-xtools/closure_linter-2.3.4/closure_linter/common/position.py126
-rwxr-xr-xtools/closure_linter-2.3.4/closure_linter/common/simplefileflags.py190
-rwxr-xr-xtools/closure_linter-2.3.4/closure_linter/common/tokenizer.py184
-rwxr-xr-xtools/closure_linter-2.3.4/closure_linter/common/tokens.py139
13 files changed, 0 insertions, 1389 deletions
diff --git a/tools/closure_linter-2.3.4/closure_linter/common/__init__.py b/tools/closure_linter-2.3.4/closure_linter/common/__init__.py
deleted file mode 100755
index 4265cc3..0000000
--- a/tools/closure_linter-2.3.4/closure_linter/common/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-#!/usr/bin/env python
diff --git a/tools/closure_linter-2.3.4/closure_linter/common/error.py b/tools/closure_linter-2.3.4/closure_linter/common/error.py
deleted file mode 100755
index 0e3b476..0000000
--- a/tools/closure_linter-2.3.4/closure_linter/common/error.py
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2007 The Closure Linter Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS-IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Error object commonly used in linters."""
-
-__author__ = ('robbyw@google.com (Robert Walker)',
- 'ajp@google.com (Andy Perelson)')
-
-
-class Error(object):
- """Object representing a style error."""
-
- def __init__(self, code, message, token, position, fix_data):
- """Initialize the error object.
-
- Args:
- code: The numeric error code.
- message: The error message string.
- token: The tokens.Token where the error occurred.
- position: The position of the error within the token.
- fix_data: Data to be used in autofixing. Codes with fix_data are:
- GOOG_REQUIRES_NOT_ALPHABETIZED - List of string value tokens that are
- class names in goog.requires calls.
- """
- self.code = code
- self.message = message
- self.token = token
- self.position = position
- if token:
- self.start_index = token.start_index
- else:
- self.start_index = 0
- self.fix_data = fix_data
- if self.position:
- self.start_index += self.position.start
-
- def Compare(a, b):
- """Compare two error objects, by source code order.
-
- Args:
- a: First error object.
- b: Second error object.
-
- Returns:
- A Negative/0/Positive number when a is before/the same as/after b.
- """
- line_diff = a.token.line_number - b.token.line_number
- if line_diff:
- return line_diff
-
- return a.start_index - b.start_index
- Compare = staticmethod(Compare)
diff --git a/tools/closure_linter-2.3.4/closure_linter/common/erroraccumulator.py b/tools/closure_linter-2.3.4/closure_linter/common/erroraccumulator.py
deleted file mode 100755
index 7bb0c97..0000000
--- a/tools/closure_linter-2.3.4/closure_linter/common/erroraccumulator.py
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2008 The Closure Linter Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS-IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Linter error handler class that accumulates an array of errors."""
-
-__author__ = ('robbyw@google.com (Robert Walker)',
- 'ajp@google.com (Andy Perelson)')
-
-
-from closure_linter.common import errorhandler
-
-
-class ErrorAccumulator(errorhandler.ErrorHandler):
- """Error handler object that accumulates errors in a list."""
-
- def __init__(self):
- self._errors = []
-
- def HandleError(self, error):
- """Append the error to the list.
-
- Args:
- error: The error object
- """
- self._errors.append((error.token.line_number, error.code))
-
- def GetErrors(self):
- """Returns the accumulated errors.
-
- Returns:
- A sequence of errors.
- """
- return self._errors
diff --git a/tools/closure_linter-2.3.4/closure_linter/common/errorhandler.py b/tools/closure_linter-2.3.4/closure_linter/common/errorhandler.py
deleted file mode 100755
index 764d54d..0000000
--- a/tools/closure_linter-2.3.4/closure_linter/common/errorhandler.py
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2008 The Closure Linter Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS-IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Interface for a linter error handler.
-
-Error handlers aggregate a set of errors from multiple files and can optionally
-perform some action based on the reported errors, for example, logging the error
-or automatically fixing it.
-"""
-
-__author__ = ('robbyw@google.com (Robert Walker)',
- 'ajp@google.com (Andy Perelson)')
-
-
-class ErrorHandler(object):
- """Error handler interface."""
-
- def __init__(self):
- if self.__class__ == ErrorHandler:
- raise NotImplementedError('class ErrorHandler is abstract')
-
- def HandleFile(self, filename, first_token):
- """Notifies this ErrorHandler that subsequent errors are in filename.
-
- Args:
- filename: The file being linted.
- first_token: The first token of the file.
- """
-
- def HandleError(self, error):
- """Append the error to the list.
-
- Args:
- error: The error object
- """
-
- def FinishFile(self):
- """Finishes handling the current file.
-
- Should be called after all errors in a file have been handled.
- """
-
- def GetErrors(self):
- """Returns the accumulated errors.
-
- Returns:
- A sequence of errors.
- """
diff --git a/tools/closure_linter-2.3.4/closure_linter/common/errorprinter.py b/tools/closure_linter-2.3.4/closure_linter/common/errorprinter.py
deleted file mode 100755
index c975406..0000000
--- a/tools/closure_linter-2.3.4/closure_linter/common/errorprinter.py
+++ /dev/null
@@ -1,203 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2008 The Closure Linter Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS-IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Linter error handler class that prints errors to stdout."""
-
-__author__ = ('robbyw@google.com (Robert Walker)',
- 'ajp@google.com (Andy Perelson)')
-
-from closure_linter.common import error
-from closure_linter.common import errorhandler
-
-Error = error.Error
-
-
-# The error message is of the format:
-# Line <number>, E:<code>: message
-DEFAULT_FORMAT = 1
-
-# The error message is of the format:
-# filename:[line number]:message
-UNIX_FORMAT = 2
-
-
-class ErrorPrinter(errorhandler.ErrorHandler):
- """ErrorHandler that prints errors to stdout."""
-
- def __init__(self, new_errors=None):
- """Initializes this error printer.
-
- Args:
- new_errors: A sequence of error codes representing recently introduced
- errors, defaults to None.
- """
- # Number of errors
- self._error_count = 0
-
- # Number of new errors
- self._new_error_count = 0
-
- # Number of files checked
- self._total_file_count = 0
-
- # Number of files with errors
- self._error_file_count = 0
-
- # Dict of file name to number of errors
- self._file_table = {}
-
- # List of errors for each file
- self._file_errors = None
-
- # Current file
- self._filename = None
-
- self._format = DEFAULT_FORMAT
-
- if new_errors:
- self._new_errors = frozenset(new_errors)
- else:
- self._new_errors = frozenset(set())
-
- def SetFormat(self, format):
- """Sets the print format of errors.
-
- Args:
- format: One of {DEFAULT_FORMAT, UNIX_FORMAT}.
- """
- self._format = format
-
- def HandleFile(self, filename, first_token):
- """Notifies this ErrorPrinter that subsequent errors are in filename.
-
- Sets the current file name, and sets a flag stating the header for this file
- has not been printed yet.
-
- Should be called by a linter before a file is style checked.
-
- Args:
- filename: The name of the file about to be checked.
- first_token: The first token in the file, or None if there was an error
- opening the file
- """
- if self._filename and self._file_table[self._filename]:
- print
-
- self._filename = filename
- self._file_table[filename] = 0
- self._total_file_count += 1
- self._file_errors = []
-
- def HandleError(self, error):
- """Prints a formatted error message about the specified error.
-
- The error message is of the format:
- Error #<code>, line #<number>: message
-
- Args:
- error: The error object
- """
- self._file_errors.append(error)
- self._file_table[self._filename] += 1
- self._error_count += 1
-
- if self._new_errors and error.code in self._new_errors:
- self._new_error_count += 1
-
- def _PrintError(self, error):
- """Prints a formatted error message about the specified error.
-
- Args:
- error: The error object
- """
- new_error = self._new_errors and error.code in self._new_errors
- if self._format == DEFAULT_FORMAT:
- line = ''
- if error.token:
- line = 'Line %d, ' % error.token.line_number
-
- code = 'E:%04d' % error.code
- if new_error:
- print '%s%s: (New error) %s' % (line, code, error.message)
- else:
- print '%s%s: %s' % (line, code, error.message)
- else:
- # UNIX format
- filename = self._filename
- line = ''
- if error.token:
- line = '%d' % error.token.line_number
-
- error_code = '%04d' % error.code
- if new_error:
- error_code = 'New Error ' + error_code
- print '%s:%s:(%s) %s' % (filename, line, error_code, error.message)
-
- def FinishFile(self):
- """Finishes handling the current file."""
- if self._file_errors:
- self._error_file_count += 1
-
- if self._format != UNIX_FORMAT:
- print '----- FILE : %s -----' % (self._filename)
-
- self._file_errors.sort(Error.Compare)
-
- for error in self._file_errors:
- self._PrintError(error)
-
- def HasErrors(self):
- """Whether this error printer encountered any errors.
-
- Returns:
- True if the error printer encountered any errors.
- """
- return self._error_count
-
- def HasNewErrors(self):
- """Whether this error printer encountered any new errors.
-
- Returns:
- True if the error printer encountered any new errors.
- """
- return self._new_error_count
-
- def HasOldErrors(self):
- """Whether this error printer encountered any old errors.
-
- Returns:
- True if the error printer encountered any old errors.
- """
- return self._error_count - self._new_error_count
-
- def PrintSummary(self):
- """Print a summary of the number of errors and files."""
- if self.HasErrors() or self.HasNewErrors():
- print ('Found %d errors, including %d new errors, in %d files '
- '(%d files OK).' % (
- self._error_count,
- self._new_error_count,
- self._error_file_count,
- self._total_file_count - self._error_file_count))
- else:
- print '%d files checked, no errors found.' % self._total_file_count
-
- def PrintFileSummary(self):
- """Print a detailed summary of the number of errors in each file."""
- keys = self._file_table.keys()
- keys.sort()
- for filename in keys:
- print '%s: %d' % (filename, self._file_table[filename])
diff --git a/tools/closure_linter-2.3.4/closure_linter/common/filetestcase.py b/tools/closure_linter-2.3.4/closure_linter/common/filetestcase.py
deleted file mode 100755
index ae4b883..0000000
--- a/tools/closure_linter-2.3.4/closure_linter/common/filetestcase.py
+++ /dev/null
@@ -1,105 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2007 The Closure Linter Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS-IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Test case that runs a checker on a file, matching errors against annotations.
-
-Runs the given checker on the given file, accumulating all errors. The list
-of errors is then matched against those annotated in the file. Based heavily
-on devtools/javascript/gpylint/full_test.py.
-"""
-
-__author__ = ('robbyw@google.com (Robert Walker)',
- 'ajp@google.com (Andy Perelson)')
-
-import re
-
-import unittest as googletest
-from closure_linter.common import erroraccumulator
-
-
-class AnnotatedFileTestCase(googletest.TestCase):
- """Test case to run a linter against a single file."""
-
- # Matches an all caps letters + underscores error identifer
- _MESSAGE = {'msg': '[A-Z][A-Z_]+'}
- # Matches a //, followed by an optional line number with a +/-, followed by a
- # list of message IDs. Used to extract expected messages from testdata files.
- # TODO(robbyw): Generalize to use different commenting patterns.
- _EXPECTED_RE = re.compile(r'\s*//\s*(?:(?P<line>[+-]?[0-9]+):)?'
- r'\s*(?P<msgs>%(msg)s(?:,\s*%(msg)s)*)' % _MESSAGE)
-
- def __init__(self, filename, runner, converter):
- """Create a single file lint test case.
-
- Args:
- filename: Filename to test.
- runner: Object implementing the LintRunner interface that lints a file.
- converter: Function taking an error string and returning an error code.
- """
-
- googletest.TestCase.__init__(self, 'runTest')
- self._filename = filename
- self._messages = []
- self._runner = runner
- self._converter = converter
-
- def shortDescription(self):
- """Provides a description for the test."""
- return 'Run linter on %s' % self._filename
-
- def runTest(self):
- """Runs the test."""
- try:
- filename = self._filename
- stream = open(filename)
- except IOError, ex:
- raise IOError('Could not find testdata resource for %s: %s' %
- (self._filename, ex))
-
- expected = self._GetExpectedMessages(stream)
- got = self._ProcessFileAndGetMessages(filename)
- self.assertEqual(expected, got)
-
- def _GetExpectedMessages(self, stream):
- """Parse a file and get a sorted list of expected messages."""
- messages = []
- for i, line in enumerate(stream):
- match = self._EXPECTED_RE.search(line)
- if match:
- line = match.group('line')
- msg_ids = match.group('msgs')
- if line is None:
- line = i + 1
- elif line.startswith('+') or line.startswith('-'):
- line = i + 1 + int(line)
- else:
- line = int(line)
- for msg_id in msg_ids.split(','):
- # Ignore a spurious message from the license preamble.
- if msg_id != 'WITHOUT':
- messages.append((line, self._converter(msg_id.strip())))
- stream.seek(0)
- messages.sort()
- return messages
-
- def _ProcessFileAndGetMessages(self, filename):
- """Trap gpylint's output parse it to get messages added."""
- errors = erroraccumulator.ErrorAccumulator()
- self._runner.Run([filename], errors)
-
- errors = errors.GetErrors()
- errors.sort()
- return errors
diff --git a/tools/closure_linter-2.3.4/closure_linter/common/htmlutil.py b/tools/closure_linter-2.3.4/closure_linter/common/htmlutil.py
deleted file mode 100755
index 26d44c5..0000000
--- a/tools/closure_linter-2.3.4/closure_linter/common/htmlutil.py
+++ /dev/null
@@ -1,170 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2007 The Closure Linter Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS-IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Utilities for dealing with HTML."""
-
-__author__ = ('robbyw@google.com (Robert Walker)')
-
-import cStringIO
-import formatter
-import htmllib
-import HTMLParser
-import re
-
-
-class ScriptExtractor(htmllib.HTMLParser):
- """Subclass of HTMLParser that extracts script contents from an HTML file.
-
- Also inserts appropriate blank lines so that line numbers in the extracted
- code match the line numbers in the original HTML.
- """
-
- def __init__(self):
- """Initialize a ScriptExtractor."""
- htmllib.HTMLParser.__init__(self, formatter.NullFormatter())
- self._in_script = False
- self._text = ''
-
- def start_script(self, attrs):
- """Internal handler for the start of a script tag.
-
- Args:
- attrs: The attributes of the script tag, as a list of tuples.
- """
- for attribute in attrs:
- if attribute[0].lower() == 'src':
- # Skip script tags with a src specified.
- return
- self._in_script = True
-
- def end_script(self):
- """Internal handler for the end of a script tag."""
- self._in_script = False
-
- def handle_data(self, data):
- """Internal handler for character data.
-
- Args:
- data: The character data from the HTML file.
- """
- if self._in_script:
- # If the last line contains whitespace only, i.e. is just there to
- # properly align a </script> tag, strip the whitespace.
- if data.rstrip(' \t') != data.rstrip(' \t\n\r\f'):
- data = data.rstrip(' \t')
- self._text += data
- else:
- self._AppendNewlines(data)
-
- def handle_comment(self, data):
- """Internal handler for HTML comments.
-
- Args:
- data: The text of the comment.
- """
- self._AppendNewlines(data)
-
- def _AppendNewlines(self, data):
- """Count the number of newlines in the given string and append them.
-
- This ensures line numbers are correct for reported errors.
-
- Args:
- data: The data to count newlines in.
- """
- # We append 'x' to both sides of the string to ensure that splitlines
- # gives us an accurate count.
- for i in xrange(len(('x' + data + 'x').splitlines()) - 1):
- self._text += '\n'
-
- def GetScriptLines(self):
- """Return the extracted script lines.
-
- Returns:
- The extracted script lines as a list of strings.
- """
- return self._text.splitlines()
-
-
-def GetScriptLines(f):
- """Extract script tag contents from the given HTML file.
-
- Args:
- f: The HTML file.
-
- Returns:
- Lines in the HTML file that are from script tags.
- """
- extractor = ScriptExtractor()
-
- # The HTML parser chokes on text like Array.<!string>, so we patch
- # that bug by replacing the < with &lt; - escaping all text inside script
- # tags would be better but it's a bit of a catch 22.
- contents = f.read()
- contents = re.sub(r'<([^\s\w/])',
- lambda x: '&lt;%s' % x.group(1),
- contents)
-
- extractor.feed(contents)
- extractor.close()
- return extractor.GetScriptLines()
-
-
-def StripTags(str):
- """Returns the string with HTML tags stripped.
-
- Args:
- str: An html string.
-
- Returns:
- The html string with all tags stripped. If there was a parse error, returns
- the text successfully parsed so far.
- """
- # Brute force approach to stripping as much HTML as possible. If there is a
- # parsing error, don't strip text before parse error position, and continue
- # trying from there.
- final_text = ''
- finished = False
- while not finished:
- try:
- strip = _HtmlStripper()
- strip.feed(str)
- strip.close()
- str = strip.get_output()
- final_text += str
- finished = True
- except HTMLParser.HTMLParseError, e:
- final_text += str[:e.offset]
- str = str[e.offset + 1:]
-
- return final_text
-
-
-class _HtmlStripper(HTMLParser.HTMLParser):
- """Simple class to strip tags from HTML.
-
- Does so by doing nothing when encountering tags, and appending character data
- to a buffer when that is encountered.
- """
- def __init__(self):
- self.reset()
- self.__output = cStringIO.StringIO()
-
- def handle_data(self, d):
- self.__output.write(d)
-
- def get_output(self):
- return self.__output.getvalue()
diff --git a/tools/closure_linter-2.3.4/closure_linter/common/lintrunner.py b/tools/closure_linter-2.3.4/closure_linter/common/lintrunner.py
deleted file mode 100755
index 07842c7..0000000
--- a/tools/closure_linter-2.3.4/closure_linter/common/lintrunner.py
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2008 The Closure Linter Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS-IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Interface for a lint running wrapper."""
-
-__author__ = ('robbyw@google.com (Robert Walker)',
- 'ajp@google.com (Andy Perelson)')
-
-
-class LintRunner(object):
- """Interface for a lint running wrapper."""
-
- def __init__(self):
- if self.__class__ == LintRunner:
- raise NotImplementedError('class LintRunner is abstract')
-
- def Run(self, filenames, error_handler):
- """Run a linter on the given filenames.
-
- Args:
- filenames: The filenames to check
- error_handler: An ErrorHandler object
-
- Returns:
- The error handler, which may have been used to collect error info.
- """
diff --git a/tools/closure_linter-2.3.4/closure_linter/common/matcher.py b/tools/closure_linter-2.3.4/closure_linter/common/matcher.py
deleted file mode 100755
index 9b4402c..0000000
--- a/tools/closure_linter-2.3.4/closure_linter/common/matcher.py
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2007 The Closure Linter Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS-IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Regular expression based JavaScript matcher classes."""
-
-__author__ = ('robbyw@google.com (Robert Walker)',
- 'ajp@google.com (Andy Perelson)')
-
-from closure_linter.common import position
-from closure_linter.common import tokens
-
-# Shorthand
-Token = tokens.Token
-Position = position.Position
-
-
-class Matcher(object):
- """A token matcher.
-
- Specifies a pattern to match, the type of token it represents, what mode the
- token changes to, and what mode the token applies to.
-
- Modes allow more advanced grammars to be incorporated, and are also necessary
- to tokenize line by line. We can have different patterns apply to different
- modes - i.e. looking for documentation while in comment mode.
-
- Attributes:
- regex: The regular expression representing this matcher.
- type: The type of token indicated by a successful match.
- result_mode: The mode to move to after a successful match.
- """
-
- def __init__(self, regex, token_type, result_mode=None, line_start=False):
- """Create a new matcher template.
-
- Args:
- regex: The regular expression to match.
- token_type: The type of token a successful match indicates.
- result_mode: What mode to change to after a successful match. Defaults to
- None, which means to not change the current mode.
- line_start: Whether this matcher should only match string at the start
- of a line.
- """
- self.regex = regex
- self.type = token_type
- self.result_mode = result_mode
- self.line_start = line_start
diff --git a/tools/closure_linter-2.3.4/closure_linter/common/position.py b/tools/closure_linter-2.3.4/closure_linter/common/position.py
deleted file mode 100755
index cebf17e..0000000
--- a/tools/closure_linter-2.3.4/closure_linter/common/position.py
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2008 The Closure Linter Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS-IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Classes to represent positions within strings."""
-
-__author__ = ('robbyw@google.com (Robert Walker)',
- 'ajp@google.com (Andy Perelson)')
-
-
-class Position(object):
- """Object representing a segment of a string.
-
- Attributes:
- start: The index in to the string where the segment starts.
- length: The length of the string segment.
- """
-
- def __init__(self, start, length):
- """Initialize the position object.
-
- Args:
- start: The start index.
- length: The number of characters to include.
- """
- self.start = start
- self.length = length
-
- def Get(self, string):
- """Returns this range of the given string.
-
- Args:
- string: The string to slice.
-
- Returns:
- The string within the range specified by this object.
- """
- return string[self.start:self.start + self.length]
-
- def Set(self, target, source):
- """Sets this range within the target string to the source string.
-
- Args:
- target: The target string.
- source: The source string.
-
- Returns:
- The resulting string
- """
- return target[:self.start] + source + target[self.start + self.length:]
-
- def AtEnd(string):
- """Create a Position representing the end of the given string.
-
- Args:
- string: The string to represent the end of.
-
- Returns:
- The created Position object.
- """
- return Position(len(string), 0)
- AtEnd = staticmethod(AtEnd)
-
- def IsAtEnd(self, string):
- """Returns whether this position is at the end of the given string.
-
- Args:
- string: The string to test for the end of.
-
- Returns:
- Whether this position is at the end of the given string.
- """
- return self.start == len(string) and self.length == 0
-
- def AtBeginning():
- """Create a Position representing the beginning of any string.
-
- Returns:
- The created Position object.
- """
- return Position(0, 0)
- AtBeginning = staticmethod(AtBeginning)
-
- def IsAtBeginning(self):
- """Returns whether this position is at the beginning of any string.
-
- Returns:
- Whether this position is at the beginning of any string.
- """
- return self.start == 0 and self.length == 0
-
- def All(string):
- """Create a Position representing the entire string.
-
- Args:
- string: The string to represent the entirety of.
-
- Returns:
- The created Position object.
- """
- return Position(0, len(string))
- All = staticmethod(All)
-
- def Index(index):
- """Returns a Position object for the specified index.
-
- Args:
- index: The index to select, inclusively.
-
- Returns:
- The created Position object.
- """
- return Position(index, 1)
- Index = staticmethod(Index)
diff --git a/tools/closure_linter-2.3.4/closure_linter/common/simplefileflags.py b/tools/closure_linter-2.3.4/closure_linter/common/simplefileflags.py
deleted file mode 100755
index 3402bef..0000000
--- a/tools/closure_linter-2.3.4/closure_linter/common/simplefileflags.py
+++ /dev/null
@@ -1,190 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2008 The Closure Linter Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS-IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Determines the list of files to be checked from command line arguments."""
-
-__author__ = ('robbyw@google.com (Robert Walker)',
- 'ajp@google.com (Andy Perelson)')
-
-import glob
-import os
-import re
-
-import gflags as flags
-
-
-FLAGS = flags.FLAGS
-
-flags.DEFINE_multistring(
- 'recurse',
- None,
- 'Recurse in to the subdirectories of the given path',
- short_name='r')
-flags.DEFINE_list(
- 'exclude_directories',
- ('_demos'),
- 'Exclude the specified directories (only applicable along with -r or '
- '--presubmit)',
- short_name='e')
-flags.DEFINE_list(
- 'exclude_files',
- ('deps.js'),
- 'Exclude the specified files',
- short_name='x')
-
-
-def MatchesSuffixes(filename, suffixes):
- """Returns whether the given filename matches one of the given suffixes.
-
- Args:
- filename: Filename to check.
- suffixes: Sequence of suffixes to check.
-
- Returns:
- Whether the given filename matches one of the given suffixes.
- """
- suffix = filename[filename.rfind('.'):]
- return suffix in suffixes
-
-
-def _GetUserSpecifiedFiles(argv, suffixes):
- """Returns files to be linted, specified directly on the command line.
-
- Can handle the '*' wildcard in filenames, but no other wildcards.
-
- Args:
- argv: Sequence of command line arguments. The second and following arguments
- are assumed to be files that should be linted.
- suffixes: Expected suffixes for the file type being checked.
-
- Returns:
- A sequence of files to be linted.
- """
- files = argv[1:] or []
- all_files = []
- lint_files = []
-
- # Perform any necessary globs.
- for f in files:
- if f.find('*') != -1:
- for result in glob.glob(f):
- all_files.append(result)
- else:
- all_files.append(f)
-
- for f in all_files:
- if MatchesSuffixes(f, suffixes):
- lint_files.append(f)
- return lint_files
-
-
-def _GetRecursiveFiles(suffixes):
- """Returns files to be checked specified by the --recurse flag.
-
- Args:
- suffixes: Expected suffixes for the file type being checked.
-
- Returns:
- A list of files to be checked.
- """
- lint_files = []
- # Perform any request recursion
- if FLAGS.recurse:
- for start in FLAGS.recurse:
- for root, subdirs, files in os.walk(start):
- for f in files:
- if MatchesSuffixes(f, suffixes):
- lint_files.append(os.path.join(root, f))
- return lint_files
-
-
-def GetAllSpecifiedFiles(argv, suffixes):
- """Returns all files specified by the user on the commandline.
-
- Args:
- argv: Sequence of command line arguments. The second and following arguments
- are assumed to be files that should be linted.
- suffixes: Expected suffixes for the file type
-
- Returns:
- A list of all files specified directly or indirectly (via flags) on the
- command line by the user.
- """
- files = _GetUserSpecifiedFiles(argv, suffixes)
-
- if FLAGS.recurse:
- files += _GetRecursiveFiles(suffixes)
-
- return FilterFiles(files)
-
-
-def FilterFiles(files):
- """Filters the list of files to be linted be removing any excluded files.
-
- Filters out files excluded using --exclude_files and --exclude_directories.
-
- Args:
- files: Sequence of files that needs filtering.
-
- Returns:
- Filtered list of files to be linted.
- """
- num_files = len(files)
-
- ignore_dirs_regexs = []
- for ignore in FLAGS.exclude_directories:
- ignore_dirs_regexs.append(re.compile(r'(^|[\\/])%s[\\/]' % ignore))
-
- result_files = []
- for f in files:
- add_file = True
- for exclude in FLAGS.exclude_files:
- if f.endswith('/' + exclude) or f == exclude:
- add_file = False
- break
- for ignore in ignore_dirs_regexs:
- if ignore.search(f):
- # Break out of ignore loop so we don't add to
- # filtered files.
- add_file = False
- break
- if add_file:
- # Convert everything to absolute paths so we can easily remove duplicates
- # using a set.
- result_files.append(os.path.abspath(f))
-
- skipped = num_files - len(result_files)
- if skipped:
- print 'Skipping %d file(s).' % skipped
-
- return set(result_files)
-
-
-def GetFileList(argv, file_type, suffixes):
- """Parse the flags and return the list of files to check.
-
- Args:
- argv: Sequence of command line arguments.
- suffixes: Sequence of acceptable suffixes for the file type.
-
- Returns:
- The list of files to check.
- """
- return sorted(GetAllSpecifiedFiles(argv, suffixes))
-
-
-def IsEmptyArgumentList(argv):
- return not (len(argv[1:]) or FLAGS.recurse)
diff --git a/tools/closure_linter-2.3.4/closure_linter/common/tokenizer.py b/tools/closure_linter-2.3.4/closure_linter/common/tokenizer.py
deleted file mode 100755
index 0234720..0000000
--- a/tools/closure_linter-2.3.4/closure_linter/common/tokenizer.py
+++ /dev/null
@@ -1,184 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2007 The Closure Linter Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS-IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Regular expression based lexer."""
-
-__author__ = ('robbyw@google.com (Robert Walker)',
- 'ajp@google.com (Andy Perelson)')
-
-from closure_linter.common import tokens
-
-# Shorthand
-Type = tokens.TokenType
-
-
-class Tokenizer(object):
- """General purpose tokenizer.
-
- Attributes:
- mode: The latest mode of the tokenizer. This allows patterns to distinguish
- if they are mid-comment, mid-parameter list, etc.
- matchers: Dictionary of modes to sequences of matchers that define the
- patterns to check at any given time.
- default_types: Dictionary of modes to types, defining what type to give
- non-matched text when in the given mode. Defaults to Type.NORMAL.
- """
-
- def __init__(self, starting_mode, matchers, default_types):
- """Initialize the tokenizer.
-
- Args:
- starting_mode: Mode to start in.
- matchers: Dictionary of modes to sequences of matchers that defines the
- patterns to check at any given time.
- default_types: Dictionary of modes to types, defining what type to give
- non-matched text when in the given mode. Defaults to Type.NORMAL.
- """
- self.__starting_mode = starting_mode
- self.matchers = matchers
- self.default_types = default_types
-
- def TokenizeFile(self, file):
- """Tokenizes the given file.
-
- Args:
- file: An iterable that yields one line of the file at a time.
-
- Returns:
- The first token in the file
- """
- # The current mode.
- self.mode = self.__starting_mode
- # The first token in the stream.
- self.__first_token = None
- # The last token added to the token stream.
- self.__last_token = None
- # The current line number.
- self.__line_number = 0
-
- for line in file:
- self.__line_number += 1
- self.__TokenizeLine(line)
-
- return self.__first_token
-
- def _CreateToken(self, string, token_type, line, line_number, values=None):
- """Creates a new Token object (or subclass).
-
- Args:
- string: The string of input the token represents.
- token_type: The type of token.
- line: The text of the line this token is in.
- line_number: The line number of the token.
- values: A dict of named values within the token. For instance, a
- function declaration may have a value called 'name' which captures the
- name of the function.
-
- Returns:
- The newly created Token object.
- """
- return tokens.Token(string, token_type, line, line_number, values)
-
- def __TokenizeLine(self, line):
- """Tokenizes the given line.
-
- Args:
- line: The contents of the line.
- """
- string = line.rstrip('\n\r\f')
- line_number = self.__line_number
- self.__start_index = 0
-
- if not string:
- self.__AddToken(self._CreateToken('', Type.BLANK_LINE, line, line_number))
- return
-
- normal_token = ''
- index = 0
- while index < len(string):
- for matcher in self.matchers[self.mode]:
- if matcher.line_start and index > 0:
- continue
-
- match = matcher.regex.match(string, index)
-
- if match:
- if normal_token:
- self.__AddToken(
- self.__CreateNormalToken(self.mode, normal_token, line,
- line_number))
- normal_token = ''
-
- # Add the match.
- self.__AddToken(self._CreateToken(match.group(), matcher.type, line,
- line_number, match.groupdict()))
-
- # Change the mode to the correct one for after this match.
- self.mode = matcher.result_mode or self.mode
-
- # Shorten the string to be matched.
- index = match.end()
-
- break
-
- else:
- # If the for loop finishes naturally (i.e. no matches) we just add the
- # first character to the string of consecutive non match characters.
- # These will constitute a NORMAL token.
- if string:
- normal_token += string[index:index + 1]
- index += 1
-
- if normal_token:
- self.__AddToken(
- self.__CreateNormalToken(self.mode, normal_token, line, line_number))
-
- def __CreateNormalToken(self, mode, string, line, line_number):
- """Creates a normal token.
-
- Args:
- mode: The current mode.
- string: The string to tokenize.
- line: The line of text.
- line_number: The line number within the file.
-
- Returns:
- A Token object, of the default type for the current mode.
- """
- type = Type.NORMAL
- if mode in self.default_types:
- type = self.default_types[mode]
- return self._CreateToken(string, type, line, line_number)
-
- def __AddToken(self, token):
- """Add the given token to the token stream.
-
- Args:
- token: The token to add.
- """
- # Store the first token, or point the previous token to this one.
- if not self.__first_token:
- self.__first_token = token
- else:
- self.__last_token.next = token
-
- # Establish the doubly linked list
- token.previous = self.__last_token
- self.__last_token = token
-
- # Compute the character indices
- token.start_index = self.__start_index
- self.__start_index += token.length
diff --git a/tools/closure_linter-2.3.4/closure_linter/common/tokens.py b/tools/closure_linter-2.3.4/closure_linter/common/tokens.py
deleted file mode 100755
index 4c7d818..0000000
--- a/tools/closure_linter-2.3.4/closure_linter/common/tokens.py
+++ /dev/null
@@ -1,139 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2008 The Closure Linter Authors. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS-IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Classes to represent tokens and positions within them."""
-
-__author__ = ('robbyw@google.com (Robert Walker)',
- 'ajp@google.com (Andy Perelson)')
-
-
-class TokenType(object):
- """Token types common to all languages."""
- NORMAL = 'normal'
- WHITESPACE = 'whitespace'
- BLANK_LINE = 'blank line'
-
-
-class Token(object):
- """Token class for intelligent text splitting.
-
- The token class represents a string of characters and an identifying type.
-
- Attributes:
- type: The type of token.
- string: The characters the token comprises.
- length: The length of the token.
- line: The text of the line the token is found in.
- line_number: The number of the line the token is found in.
- values: Dictionary of values returned from the tokens regex match.
- previous: The token before this one.
- next: The token after this one.
- start_index: The character index in the line where this token starts.
- attached_object: Object containing more information about this token.
- metadata: Object containing metadata about this token. Must be added by
- a separate metadata pass.
- """
-
- def __init__(self, string, token_type, line, line_number, values=None):
- """Creates a new Token object.
-
- Args:
- string: The string of input the token contains.
- token_type: The type of token.
- line: The text of the line this token is in.
- line_number: The line number of the token.
- values: A dict of named values within the token. For instance, a
- function declaration may have a value called 'name' which captures the
- name of the function.
- """
- self.type = token_type
- self.string = string
- self.length = len(string)
- self.line = line
- self.line_number = line_number
- self.values = values
-
- # These parts can only be computed when the file is fully tokenized
- self.previous = None
- self.next = None
- self.start_index = None
-
- # This part is set in statetracker.py
- # TODO(robbyw): Wrap this in to metadata
- self.attached_object = None
-
- # This part is set in *metadatapass.py
- self.metadata = None
-
- def IsFirstInLine(self):
- """Tests if this token is the first token in its line.
-
- Returns:
- Whether the token is the first token in its line.
- """
- return not self.previous or self.previous.line_number != self.line_number
-
- def IsLastInLine(self):
- """Tests if this token is the last token in its line.
-
- Returns:
- Whether the token is the last token in its line.
- """
- return not self.next or self.next.line_number != self.line_number
-
- def IsType(self, token_type):
- """Tests if this token is of the given type.
-
- Args:
- token_type: The type to test for.
-
- Returns:
- True if the type of this token matches the type passed in.
- """
- return self.type == token_type
-
- def IsAnyType(self, *token_types):
- """Tests if this token is any of the given types.
-
- Args:
- token_types: The types to check. Also accepts a single array.
-
- Returns:
- True if the type of this token is any of the types passed in.
- """
- if not isinstance(token_types[0], basestring):
- return self.type in token_types[0]
- else:
- return self.type in token_types
-
- def __repr__(self):
- return '<Token: %s, "%s", %r, %d, %r>' % (self.type, self.string,
- self.values, self.line_number,
- self.metadata)
-
- def __iter__(self):
- """Returns a token iterator."""
- node = self
- while node:
- yield node
- node = node.next
-
- def __reversed__(self):
- """Returns a reverse-direction token iterator."""
- node = self
- while node:
- yield node
- node = node.previous