Permalink
Browse files

Merged dashersw/GUI-tools as a subtree at tools

  • Loading branch information...
2 parents 661a93f + 4bc5778 commit 0724c6e1c40bb55b3dd91364add2327f78891a15 @dashersw committed Apr 9, 2011
Showing with 9,209 additions and 0 deletions.
  1. 0 tools/README
  2. +10 −0 tools/closure_linter-2.2.7/PKG-INFO
  3. +9 −0 tools/closure_linter-2.2.7/README
  4. +1 −0 tools/closure_linter-2.2.7/closure_linter/__init__.py
  5. +82 −0 tools/closure_linter-2.2.7/closure_linter/checker.py
  6. +248 −0 tools/closure_linter-2.2.7/closure_linter/checkerbase.py
  7. +1 −0 tools/closure_linter-2.2.7/closure_linter/common/__init__.py
  8. +65 −0 tools/closure_linter-2.2.7/closure_linter/common/error.py
  9. +46 −0 tools/closure_linter-2.2.7/closure_linter/common/erroraccumulator.py
  10. +61 −0 tools/closure_linter-2.2.7/closure_linter/common/errorhandler.py
  11. +203 −0 tools/closure_linter-2.2.7/closure_linter/common/errorprinter.py
  12. +105 −0 tools/closure_linter-2.2.7/closure_linter/common/filetestcase.py
  13. +170 −0 tools/closure_linter-2.2.7/closure_linter/common/htmlutil.py
  14. +39 −0 tools/closure_linter-2.2.7/closure_linter/common/lintrunner.py
  15. +60 −0 tools/closure_linter-2.2.7/closure_linter/common/matcher.py
  16. +126 −0 tools/closure_linter-2.2.7/closure_linter/common/position.py
  17. +190 −0 tools/closure_linter-2.2.7/closure_linter/common/simplefileflags.py
  18. +184 −0 tools/closure_linter-2.2.7/closure_linter/common/tokenizer.py
  19. +125 −0 tools/closure_linter-2.2.7/closure_linter/common/tokens.py
  20. +754 −0 tools/closure_linter-2.2.7/closure_linter/ecmalintrules.py
  21. +521 −0 tools/closure_linter-2.2.7/closure_linter/ecmametadatapass.py
  22. +336 −0 tools/closure_linter-2.2.7/closure_linter/error_fixer.py
  23. +42 −0 tools/closure_linter-2.2.7/closure_linter/errorrules.py
  24. +131 −0 tools/closure_linter-2.2.7/closure_linter/errors.py
  25. +47 −0 tools/closure_linter-2.2.7/closure_linter/fixjsstyle.py
  26. +61 −0 tools/closure_linter-2.2.7/closure_linter/fixjsstyle_test.py
  27. +101 −0 tools/closure_linter-2.2.7/closure_linter/full_test.py
  28. +142 −0 tools/closure_linter-2.2.7/closure_linter/gjslint.py
  29. +543 −0 tools/closure_linter-2.2.7/closure_linter/indentation.py
  30. +395 −0 tools/closure_linter-2.2.7/closure_linter/javascriptlintrules.py
  31. +238 −0 tools/closure_linter-2.2.7/closure_linter/javascriptstatetracker.py
  32. +53 −0 tools/closure_linter-2.2.7/closure_linter/javascriptstatetracker_test.py
  33. +367 −0 tools/closure_linter-2.2.7/closure_linter/javascripttokenizer.py
  34. +147 −0 tools/closure_linter-2.2.7/closure_linter/javascripttokens.py
  35. +965 −0 tools/closure_linter-2.2.7/closure_linter/statetracker.py
  36. +285 −0 tools/closure_linter-2.2.7/closure_linter/tokenutil.py
  37. +38 −0 tools/closure_linter-2.2.7/setup.py
  38. +257 −0 tools/goog/build/closurebuilder.py
  39. +186 −0 tools/goog/build/depstree.py
  40. +127 −0 tools/goog/build/depstree_test.py
  41. +197 −0 tools/goog/build/depswriter.py
  42. +69 −0 tools/goog/build/jscompiler.py
  43. +86 −0 tools/goog/build/source.py
  44. +57 −0 tools/goog/build/source_test.py
  45. +78 −0 tools/goog/build/treescan.py
  46. +570 −0 tools/goog/calcdeps.py
  47. +202 −0 tools/goog/compiler/COPYING
  48. +278 −0 tools/goog/compiler/README
  49. BIN tools/goog/compiler/compiler.jar
  50. +211 −0 tools/goog/scopify.py
View
No changes.
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: closure_linter
+Version: 2.2.7
+Summary: Closure Linter
+Home-page: http://code.google.com/p/closure-linter
+Author: The Closure Linter Authors
+Author-email: opensource@google.com
+License: Apache
+Description: UNKNOWN
+Platform: UNKNOWN
@@ -0,0 +1,9 @@
+This repository contains the Closure Linter - a style checker for JavaScript.
+
+To install the application, run
+ python ./setup.py install
+
+After installing, you get two helper applications installed into /usr/local/bin:
+
+ gjslint.py - runs the linter and checks for errors
+ fixjsstyle.py - tries to fix errors automatically
@@ -0,0 +1 @@
+#!/usr/bin/env python
@@ -0,0 +1,82 @@
+#!/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.
+
+"""Core methods for checking JS files for common style guide violations."""
+
+__author__ = ('robbyw@google.com (Robert Walker)',
+ 'ajp@google.com (Andy Perelson)')
+
+import gflags as flags
+
+from closure_linter import checkerbase
+from closure_linter import ecmametadatapass
+from closure_linter import errors
+from closure_linter import javascriptlintrules
+from closure_linter import javascriptstatetracker
+from closure_linter.common import errorprinter
+from closure_linter.common import lintrunner
+
+flags.DEFINE_list('limited_doc_files', ['dummy.js', 'externs.js'],
+ 'List of files with relaxed documentation checks. Will not '
+ 'report errors for missing documentation, some missing '
+ 'descriptions, or methods whose @return tags don\'t have a '
+ 'matching return statement.')
+
+
+class JavaScriptStyleChecker(checkerbase.CheckerBase):
+ """Checker that applies JavaScriptLintRules."""
+
+ def __init__(self, error_handler):
+ """Initialize an JavaScriptStyleChecker object.
+
+ Args:
+ error_handler: Error handler to pass all errors to
+ """
+ checkerbase.CheckerBase.__init__(
+ self,
+ error_handler=error_handler,
+ lint_rules=javascriptlintrules.JavaScriptLintRules(),
+ state_tracker=javascriptstatetracker.JavaScriptStateTracker(
+ closurized_namespaces=flags.FLAGS.closurized_namespaces),
+ metadata_pass=ecmametadatapass.EcmaMetaDataPass(),
+ limited_doc_files=flags.FLAGS.limited_doc_files)
+
+
+class GJsLintRunner(lintrunner.LintRunner):
+ """Wrapper class to run GJsLint."""
+
+ def Run(self, filenames, error_handler=None):
+ """Run GJsLint on the given filenames.
+
+ Args:
+ filenames: The filenames to check
+ error_handler: An optional ErrorHandler object, an ErrorPrinter is used if
+ none is specified.
+
+ Returns:
+ error_count, file_count: The number of errors and the number of files that
+ contain errors.
+ """
+ if not error_handler:
+ error_handler = errorprinter.ErrorPrinter(errors.NEW_ERRORS)
+
+ checker = JavaScriptStyleChecker(error_handler)
+
+ # Check the list of files.
+ for filename in filenames:
+ checker.Check(filename)
+
+ return error_handler
@@ -0,0 +1,248 @@
+#!/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.
+
+"""Base classes for writing checkers that operate on tokens."""
+
+__author__ = ('robbyw@google.com (Robert Walker)',
+ 'ajp@google.com (Andy Perelson)',
+ 'jacobr@google.com (Jacob Richman)')
+
+import StringIO
+import traceback
+
+import gflags as flags
+from closure_linter import ecmametadatapass
+from closure_linter import errorrules
+from closure_linter import errors
+from closure_linter import javascripttokenizer
+from closure_linter.common import error
+from closure_linter.common import htmlutil
+
+FLAGS = flags.FLAGS
+flags.DEFINE_boolean('debug_tokens', False,
+ 'Whether to print all tokens for debugging.')
+
+flags.DEFINE_boolean('error_trace', False,
+ 'Whether to show error exceptions.')
+
+class LintRulesBase(object):
+ """Base class for all classes defining the lint rules for a language."""
+
+ def __init__(self):
+ self.__checker = None
+
+ def Initialize(self, checker, limited_doc_checks, is_html):
+ """Initializes to prepare to check a file.
+
+ Args:
+ checker: Class to report errors to.
+ limited_doc_checks: Whether doc checking is relaxed for this file.
+ is_html: Whether the file is an HTML file with extracted contents.
+ """
+ self.__checker = checker
+ self._limited_doc_checks = limited_doc_checks
+ self._is_html = is_html
+
+ def _HandleError(self, code, message, token, position=None,
+ fix_data=None):
+ """Call the HandleError function for the checker we are associated with."""
+ if errorrules.ShouldReportError(code):
+ self.__checker.HandleError(code, message, token, position, fix_data)
+
+ def CheckToken(self, token, parser_state):
+ """Checks a token, given the current parser_state, for warnings and errors.
+
+ Args:
+ token: The current token under consideration.
+ parser_state: Object that indicates the parser state in the page.
+
+ Raises:
+ TypeError: If not overridden.
+ """
+ raise TypeError('Abstract method CheckToken not implemented')
+
+ def Finalize(self, parser_state, tokenizer_mode):
+ """Perform all checks that need to occur after all lines are processed.
+
+ Args:
+ parser_state: State of the parser after parsing all tokens
+ tokenizer_mode: Mode of the tokenizer after parsing the entire page
+
+ Raises:
+ TypeError: If not overridden.
+ """
+ raise TypeError('Abstract method Finalize not implemented')
+
+
+class CheckerBase(object):
+ """This class handles checking a LintRules object against a file."""
+
+ def __init__(self, error_handler, lint_rules, state_tracker,
+ limited_doc_files=None, metadata_pass=None):
+ """Initialize a checker object.
+
+ Args:
+ error_handler: Object that handles errors.
+ lint_rules: LintRules object defining lint errors given a token
+ and state_tracker object.
+ state_tracker: Object that tracks the current state in the token stream.
+ limited_doc_files: List of filenames that are not required to have
+ documentation comments.
+ metadata_pass: Object that builds metadata about the token stream.
+ """
+ self.__error_handler = error_handler
+ self.__lint_rules = lint_rules
+ self.__state_tracker = state_tracker
+ self.__metadata_pass = metadata_pass
+ self.__limited_doc_files = limited_doc_files
+ self.__tokenizer = javascripttokenizer.JavaScriptTokenizer()
+ self.__has_errors = False
+
+ def HandleError(self, code, message, token, position=None,
+ fix_data=None):
+ """Prints out the given error message including a line number.
+
+ Args:
+ code: The error code.
+ message: The error to print.
+ token: The token where the error occurred, or None if it was a file-wide
+ issue.
+ position: The position of the error, defaults to None.
+ fix_data: Metadata used for fixing the error.
+ """
+ self.__has_errors = True
+ self.__error_handler.HandleError(
+ error.Error(code, message, token, position, fix_data))
+
+ def HasErrors(self):
+ """Returns true if the style checker has found any errors.
+
+ Returns:
+ True if the style checker has found any errors.
+ """
+ return self.__has_errors
+
+ def Check(self, filename, source=None):
+ """Checks the file, printing warnings and errors as they are found.
+
+ Args:
+ filename: The name of the file to check.
+ source: Optional. The contents of the file. Can be either a string or
+ file-like object. If omitted, contents will be read from disk from
+ the given filename.
+ """
+
+ if source is None:
+ try:
+ f = open(filename)
+ except IOError:
+ self.__error_handler.HandleFile(filename, None)
+ self.HandleError(errors.FILE_NOT_FOUND, 'File not found', None)
+ self.__error_handler.FinishFile()
+ return
+ else:
+ if type(source) in [str, unicode]:
+ f = StringIO.StringIO(source)
+ else:
+ f = source
+
+ try:
+ if filename.endswith('.html') or filename.endswith('.htm'):
+ self.CheckLines(filename, htmlutil.GetScriptLines(f), True)
+ else:
+ self.CheckLines(filename, f, False)
+ finally:
+ f.close()
+
+ def CheckLines(self, filename, lines_iter, is_html):
+ """Checks a file, given as an iterable of lines, for warnings and errors.
+
+ Args:
+ filename: The name of the file to check.
+ lines_iter: An iterator that yields one line of the file at a time.
+ is_html: Whether the file being checked is an HTML file with extracted
+ contents.
+
+ Returns:
+ A boolean indicating whether the full file could be checked or if checking
+ failed prematurely.
+ """
+ limited_doc_checks = False
+ if self.__limited_doc_files:
+ for limited_doc_filename in self.__limited_doc_files:
+ if filename.endswith(limited_doc_filename):
+ limited_doc_checks = True
+ break
+
+ state_tracker = self.__state_tracker
+ lint_rules = self.__lint_rules
+ state_tracker.Reset()
+ lint_rules.Initialize(self, limited_doc_checks, is_html)
+
+ token = self.__tokenizer.TokenizeFile(lines_iter)
+
+ parse_error = None
+ if self.__metadata_pass:
+ try:
+ self.__metadata_pass.Reset()
+ self.__metadata_pass.Process(token)
+ except ecmametadatapass.ParseError, caught_parse_error:
+ if FLAGS.error_trace:
+ traceback.print_exc()
+ parse_error = caught_parse_error
+ except Exception:
+ print 'Internal error in %s' % filename
+ traceback.print_exc()
+ return False
+
+ self.__error_handler.HandleFile(filename, token)
+
+ while token:
+ if FLAGS.debug_tokens:
+ print token
+
+ if parse_error and parse_error.token == token:
+ # Report any parse errors from above once we find the token.
+ message = ('Error parsing file at token "%s". Unable to '
+ 'check the rest of file.' % token.string)
+ self.HandleError(errors.FILE_DOES_NOT_PARSE, message, token)
+ self.__error_handler.FinishFile()
+ return False
+
+ if FLAGS.error_trace:
+ state_tracker.HandleToken(token, state_tracker.GetLastNonSpaceToken())
+ else:
+ try:
+ state_tracker.HandleToken(token, state_tracker.GetLastNonSpaceToken())
+ except:
+ self.HandleError(errors.FILE_DOES_NOT_PARSE,
+ ('Error parsing file at token "%s". Unable to '
+ 'check the rest of file.' % token.string),
+ token)
+ self.__error_handler.FinishFile()
+ return False
+
+ # Check the token for style guide violations.
+ lint_rules.CheckToken(token, state_tracker)
+
+ state_tracker.HandleAfterToken(token)
+
+ # Move to the next token.
+ token = token.next
+
+ lint_rules.Finalize(state_tracker, self.__tokenizer.mode)
+ self.__error_handler.FinishFile()
+ return True
@@ -0,0 +1 @@
+#!/usr/bin/env python
Oops, something went wrong.

0 comments on commit 0724c6e

Please sign in to comment.