Skip to content
Browse files

main api and jslint done

  • Loading branch information...
1 parent e3b8fde commit f8148535b44fbf23b03df0dd9fdc687b1040e395 @kof committed
Showing with 7,545 additions and 24 deletions.
  1. +1 −1 conf/server.json
  2. +1 −0 deps/JSLint
  3. +202 −0 deps/closure-compiler/COPYING
  4. +289 −0 deps/closure-compiler/README
  5. BIN deps/closure-compiler/compiler.jar
  6. +10 −0 deps/closure_linter/PKG-INFO
  7. +9 −0 deps/closure_linter/README
  8. +10 −0 deps/closure_linter/closure_linter.egg-info/PKG-INFO
  9. +41 −0 deps/closure_linter/closure_linter.egg-info/SOURCES.txt
  10. +1 −0 deps/closure_linter/closure_linter.egg-info/dependency_links.txt
  11. +4 −0 deps/closure_linter/closure_linter.egg-info/entry_points.txt
  12. +1 −0 deps/closure_linter/closure_linter.egg-info/requires.txt
  13. +1 −0 deps/closure_linter/closure_linter.egg-info/top_level.txt
  14. +1 −0 deps/closure_linter/closure_linter/__init__.py
  15. +82 −0 deps/closure_linter/closure_linter/checker.py
  16. +237 −0 deps/closure_linter/closure_linter/checkerbase.py
  17. +1 −0 deps/closure_linter/closure_linter/common/__init__.py
  18. +65 −0 deps/closure_linter/closure_linter/common/error.py
  19. +46 −0 deps/closure_linter/closure_linter/common/erroraccumulator.py
  20. +61 −0 deps/closure_linter/closure_linter/common/errorhandler.py
  21. +203 −0 deps/closure_linter/closure_linter/common/errorprinter.py
  22. +105 −0 deps/closure_linter/closure_linter/common/filetestcase.py
  23. +170 −0 deps/closure_linter/closure_linter/common/htmlutil.py
  24. +39 −0 deps/closure_linter/closure_linter/common/lintrunner.py
  25. +60 −0 deps/closure_linter/closure_linter/common/matcher.py
  26. +126 −0 deps/closure_linter/closure_linter/common/position.py
  27. +190 −0 deps/closure_linter/closure_linter/common/simplefileflags.py
  28. +184 −0 deps/closure_linter/closure_linter/common/tokenizer.py
  29. +125 −0 deps/closure_linter/closure_linter/common/tokens.py
  30. +752 −0 deps/closure_linter/closure_linter/ecmalintrules.py
  31. +521 −0 deps/closure_linter/closure_linter/ecmametadatapass.py
  32. +336 −0 deps/closure_linter/closure_linter/error_fixer.py
  33. +42 −0 deps/closure_linter/closure_linter/errorrules.py
  34. +131 −0 deps/closure_linter/closure_linter/errors.py
  35. +47 −0 deps/closure_linter/closure_linter/fixjsstyle.py
  36. +61 −0 deps/closure_linter/closure_linter/fixjsstyle_test.py
  37. +99 −0 deps/closure_linter/closure_linter/full_test.py
  38. +142 −0 deps/closure_linter/closure_linter/gjslint.py
  39. +543 −0 deps/closure_linter/closure_linter/indentation.py
  40. +395 −0 deps/closure_linter/closure_linter/javascriptlintrules.py
  41. +238 −0 deps/closure_linter/closure_linter/javascriptstatetracker.py
  42. +53 −0 deps/closure_linter/closure_linter/javascriptstatetracker_test.py
  43. +365 −0 deps/closure_linter/closure_linter/javascripttokenizer.py
  44. +147 −0 deps/closure_linter/closure_linter/javascripttokens.py
  45. +964 −0 deps/closure_linter/closure_linter/statetracker.py
  46. +285 −0 deps/closure_linter/closure_linter/tokenutil.py
  47. +5 −0 deps/closure_linter/setup.cfg
  48. +38 −0 deps/closure_linter/setup.py
  49. +1 −0 index.js
  50. +65 −0 lib/codenazi.js
  51. +32 −23 lib/jslint.js
  52. +2 −0 test/fixture.js
  53. +16 −0 test/test.js
View
2 conf/server.json
@@ -20,7 +20,7 @@
"onevar": true,
"passfail": true,
"plusplus": false,
- "predef": ["global", "process", "require", "__dirname", "__filename", "module", "exports"],
+ "predef": ["global", "process", "require", "__dirname", "__filename", "module", "exports", "Buffer"],
"regexp": true,
"rhino": false,
"safe": false,
1 deps/JSLint
@@ -0,0 +1 @@
+Subproject commit dc4a01335c71f19b383cf53eca6c691a6012410b
View
202 deps/closure-compiler/COPYING
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
View
289 deps/closure-compiler/README
@@ -0,0 +1,289 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * 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.
+ */
+
+//
+// Contents
+//
+
+The Closure Compiler performs checking, instrumentation, and
+optimizations on JavaScript code. The purpose of this README is to
+explain how to build and run the Closure Compiler.
+
+The Closure Compiler requires Java 6 or higher.
+http://www.java.com/
+
+
+//
+// Building The Closure Compiler
+//
+
+There are three ways to get a Closure Compiler executable.
+
+1) Use one we built for you.
+
+Pre-built Closure binaries can be found at
+http://code.google.com/p/closure-compiler/downloads/list
+
+
+2) Check out the source and build it with Apache Ant.
+
+First, check out the full source tree of the Closure Compiler. There
+are instructions on how to do this at the project site.
+http://code.google.com/p/closure-compiler/source/checkout
+
+Apache Ant is a cross-platform build tool.
+http://ant.apache.org/
+
+At the root of the source tree, there is an Ant file named
+build.xml. To use it, navigate to the same directory and type the
+command
+
+ant jar
+
+This will produce a jar file called "build/compiler.jar".
+
+
+3) Check out the source and build it with Eclipse.
+
+Eclipse is a cross-platform IDE.
+http://www.eclipse.org/
+
+Under Eclipse's File menu, click "New > Project ..." and create a
+"Java Project." You will see an options screen. Give the project a
+name, select "Create project from existing source," and choose the
+root of the checked-out source tree as the existing directory. Verify
+that you are using JRE version 6 or higher.
+
+Eclipse can use the build.xml file to discover rules. When you
+navigate to the build.xml file, you will see all the build rules in
+the "Outline" pane. Run the "jar" rule to build the compiler in
+build/compiler.jar.
+
+
+//
+// Running The Closure Compiler
+//
+
+Once you have the jar binary, running the Closure Compiler is straightforward.
+
+On the command line, type
+
+java -jar compiler.jar
+
+This starts the compiler in interactive mode. Type
+
+var x = 17 + 25;
+
+then hit "Enter", then hit "Ctrl-Z" (on Windows) or "Ctrl-D" (on Mac or Linux)
+and "Enter" again. The Compiler will respond:
+
+var x=42;
+
+The Closure Compiler has many options for reading input from a file,
+writing output to a file, checking your code, and running
+optimizations. To learn more, type
+
+java -jar compiler.jar --help
+
+You can read more detailed documentation about the many flags at
+http://code.google.com/closure/compiler/docs/gettingstarted_app.html
+
+
+//
+// Compiling Multiple Scripts
+//
+
+If you have multiple scripts, you should compile them all together with
+one compile command.
+
+java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js
+
+The Closure Compiler will concatenate the files in the order they're
+passed at the command line.
+
+If you need to compile many, many scripts together, you may start to
+run into problems with managing dependencies between scripts. You
+should check out the Closure Library. It contains functions for
+enforcing dependencies between scripts, and a tool called calcdeps.py
+that knows how to give scripts to the Closure Compiler in the right
+order.
+
+http://code.google.com/p/closure-library/
+
+//
+// Licensing
+//
+
+Unless otherwise stated, all source files are licensed under
+the Apache License, Version 2.0.
+
+
+-----
+Code under:
+src/com/google/javascript/rhino
+test/com/google/javascript/rhino
+
+URL: http://www.mozilla.org/rhino
+Version: 1.5R3, with heavy modifications
+License: Netscape Public License and MPL / GPL dual license
+
+Description: A partial copy of Mozilla Rhino. Mozilla Rhino is an
+implementation of JavaScript for the JVM. The JavaScript parser and
+the parse tree data structures were extracted and modified
+significantly for use by Google's JavaScript compiler.
+
+Local Modifications: The packages have been renamespaced. All code not
+relavant to parsing has been removed. A JSDoc parser and static typing
+system have been added.
+
+
+-----
+Code in:
+lib/libtrunk_rhino_parser_jarjared.jar
+
+Rhino
+URL: http://www.mozilla.org/rhino
+Version: Trunk
+License: Netscape Public License and MPL / GPL dual license
+
+Description: Mozilla Rhino is an implementation of JavaScript for the JVM.
+
+Local Modifications: None. We've used JarJar to renamespace the code
+post-compilation. See:
+http://code.google.com/p/jarjar/
+
+
+-----
+Code in:
+lib/args4j_deploy.jar
+
+Args4j
+URL: https://args4j.dev.java.net/
+Version: 2.0.9
+License: MIT
+
+Description:
+args4j is a small Java class library that makes it easy to parse command line
+options/arguments in your CUI application.
+
+Local Modifications: None.
+
+
+-----
+Code in:
+lib/guava-r06.jar
+
+Guava Libraries
+URL: http://code.google.com/p/guava-libraries/
+Version: R6
+License: Apache License 2.0
+
+Description: Google's core Java libraries.
+
+Local Modifications: None.
+
+
+-----
+Code in:
+lib/hamcrest-core-1.1.jar
+
+Hamcrest
+URL: http://code.google.com/p/hamcrest
+License: BSD
+License File: LICENSE
+
+Description:
+Provides a library of matcher objects (also known as constraints or
+predicates) allowing 'match' rules to be defined declaratively, to be used in
+other frameworks. Typical scenarios include testing frameworks, mocking
+libraries and UI validation rules.
+
+Local modifications:
+The original jars contained both source code and compiled classes.
+
+hamcrest-core-1.1.jar just contains the compiled classes.
+
+
+
+-----
+Code in:
+lib/jsr305.jar
+
+Annotations for software defect detection
+URL: http://code.google.com/p/jsr-305/
+Version: svn revision 47
+License: BSD License
+
+Description: Annotations for software defect detection.
+
+Local Modifications: None.
+
+
+----
+Code in:
+lib/junit.jar
+
+JUnit
+URL: http://sourceforge.net/projects/junit/
+Version: 4.5
+License: Common Public License 1.0
+
+Description: A framework for writing and running automated tests in Java.
+
+Local Modifications: None.
+
+
+---
+Code in:
+lib/protobuf-java-2.3.0.jar
+
+Protocol Buffers
+URL: http://code.google.com/p/protobuf/
+Version: 2.3.0
+License: New BSD License
+
+Description: Supporting libraries for protocol buffers,
+an encoding of structured data.
+
+Local Modifications: None
+
+
+---
+Code in:
+lib/ant_deploy.jar
+
+URL: http://ant.apache.org/bindownload.cgi
+Version: 1.6.5
+License: Apache License 2.0
+Description:
+ Ant is a Java based build tool. In theory it is kind of like "make"
+ without make's wrinkles and with the full portability of pure java code.
+
+Local Modifications:
+ Modified apache-ant-1.6.5/bin/ant to look in the ant.runfiles directory
+
+
+---
+Code in:
+lib/json.jar
+URL: http://json.org/java/index.html
+Version: JSON version 2
+License: MIT license
+Description:
+JSON is a set of java files for use in transmitting data in JSON format.
+
+Local Modifications: None
+
View
BIN deps/closure-compiler/compiler.jar
Binary file not shown.
View
10 deps/closure_linter/PKG-INFO
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: closure_linter
+Version: 2.2.6
+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
View
9 deps/closure_linter/README
@@ -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
View
10 deps/closure_linter/closure_linter.egg-info/PKG-INFO
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: closure-linter
+Version: 2.2.6
+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
View
41 deps/closure_linter/closure_linter.egg-info/SOURCES.txt
@@ -0,0 +1,41 @@
+README
+setup.py
+closure_linter/__init__.py
+closure_linter/checker.py
+closure_linter/checkerbase.py
+closure_linter/ecmalintrules.py
+closure_linter/ecmametadatapass.py
+closure_linter/error_fixer.py
+closure_linter/errorrules.py
+closure_linter/errors.py
+closure_linter/fixjsstyle.py
+closure_linter/fixjsstyle_test.py
+closure_linter/full_test.py
+closure_linter/gjslint.py
+closure_linter/indentation.py
+closure_linter/javascriptlintrules.py
+closure_linter/javascriptstatetracker.py
+closure_linter/javascriptstatetracker_test.py
+closure_linter/javascripttokenizer.py
+closure_linter/javascripttokens.py
+closure_linter/statetracker.py
+closure_linter/tokenutil.py
+closure_linter.egg-info/PKG-INFO
+closure_linter.egg-info/SOURCES.txt
+closure_linter.egg-info/dependency_links.txt
+closure_linter.egg-info/entry_points.txt
+closure_linter.egg-info/requires.txt
+closure_linter.egg-info/top_level.txt
+closure_linter/common/__init__.py
+closure_linter/common/error.py
+closure_linter/common/erroraccumulator.py
+closure_linter/common/errorhandler.py
+closure_linter/common/errorprinter.py
+closure_linter/common/filetestcase.py
+closure_linter/common/htmlutil.py
+closure_linter/common/lintrunner.py
+closure_linter/common/matcher.py
+closure_linter/common/position.py
+closure_linter/common/simplefileflags.py
+closure_linter/common/tokenizer.py
+closure_linter/common/tokens.py
View
1 deps/closure_linter/closure_linter.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
View
4 deps/closure_linter/closure_linter.egg-info/entry_points.txt
@@ -0,0 +1,4 @@
+[console_scripts]
+fixjsstyle = closure_linter.fixjsstyle:main
+gjslint = closure_linter.gjslint:main
+
View
1 deps/closure_linter/closure_linter.egg-info/requires.txt
@@ -0,0 +1 @@
+python-gflags
View
1 deps/closure_linter/closure_linter.egg-info/top_level.txt
@@ -0,0 +1 @@
+closure_linter
View
1 deps/closure_linter/closure_linter/__init__.py
@@ -0,0 +1 @@
+#!/usr/bin/env python
View
82 deps/closure_linter/closure_linter/checker.py
@@ -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
View
237 deps/closure_linter/closure_linter/checkerbase.py
@@ -0,0 +1,237 @@
+#!/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 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):
+ """Checks the file, printing warnings and errors as they are found.
+
+ Args:
+ filename: The name of the file to check.
+ """
+ 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
+
+ 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
View
1 deps/closure_linter/closure_linter/common/__init__.py
@@ -0,0 +1 @@
+#!/usr/bin/env python
View
65 deps/closure_linter/closure_linter/common/error.py
@@ -0,0 +1,65 @@
+#!/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)
View
46 deps/closure_linter/closure_linter/common/erroraccumulator.py
@@ -0,0 +1,46 @@
+#!/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
View
61 deps/closure_linter/closure_linter/common/errorhandler.py
@@ -0,0 +1,61 @@
+#!/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.
+ """
View
203 deps/closure_linter/closure_linter/common/errorprinter.py
@@ -0,0 +1,203 @@
+#!/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])
View
105 deps/closure_linter/closure_linter/common/filetestcase.py
@@ -0,0 +1,105 @@
+#!/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
View
170 deps/closure_linter/closure_linter/common/htmlutil.py
@@ -0,0 +1,170 @@
+#!/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()
View
39 deps/closure_linter/closure_linter/common/lintrunner.py
@@ -0,0 +1,39 @@
+#!/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.
+ """
View
60 deps/closure_linter/closure_linter/common/matcher.py
@@ -0,0 +1,60 @@
+#!/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
View
126 deps/closure_linter/closure_linter/common/position.py
@@ -0,0 +1,126 @@
+#!/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)
View
190 deps/closure_linter/closure_linter/common/simplefileflags.py
@@ -0,0 +1,190 @@
+#!/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)
View
184 deps/closure_linter/closure_linter/common/tokenizer.py
@@ -0,0 +1,184 @@
+#!/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
View
125 deps/closure_linter/closure_linter/common/tokens.py
@@ -0,0 +1,125 @@
+#!/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)
View
752 deps/closure_linter/closure_linter/ecmalintrules.py
@@ -0,0 +1,752 @@
+#!/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.
+
+"""Core methods for checking EcmaScript files for common style guide violations.
+"""
+
+__author__ = ('robbyw@google.com (Robert Walker)',
+ 'ajp@google.com (Andy Perelson)',
+ 'jacobr@google.com (Jacob Richman)')
+
+import re
+
+from closure_linter import checkerbase
+from closure_linter import ecmametadatapass
+from closure_linter import errors
+from closure_linter import indentation
+from closure_linter import javascripttokens
+from closure_linter import javascripttokenizer
+from closure_linter import statetracker
+from closure_linter import tokenutil
+from closure_linter.common import error
+from closure_linter.common import htmlutil
+from closure_linter.common import lintrunner
+from closure_linter.common import position
+from closure_linter.common import tokens
+import gflags as flags
+
+FLAGS = flags.FLAGS
+flags.DEFINE_boolean('strict', False,
+ 'Whether to validate against the stricter Closure style.')
+flags.DEFINE_list('custom_jsdoc_tags', '', 'Extra j