[javascriptlint-commit] SF.net SVN: javascriptlint:[258] trunk/javascriptlint
Status: Beta
Brought to you by:
matthiasmiller
|
From: <mat...@us...> - 2009-10-03 18:10:14
|
Revision: 258
http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=258&view=rev
Author: matthiasmiller
Date: 2009-10-03 18:10:05 +0000 (Sat, 03 Oct 2009)
Log Message:
-----------
Implement --help:conf.
Modified Paths:
--------------
trunk/javascriptlint/conf.py
trunk/javascriptlint/jsl.py
trunk/javascriptlint/warnings.py
Modified: trunk/javascriptlint/conf.py
===================================================================
--- trunk/javascriptlint/conf.py 2009-10-03 17:39:40 UTC (rev 257)
+++ trunk/javascriptlint/conf.py 2009-10-03 18:10:05 UTC (rev 258)
@@ -1,8 +1,90 @@
# vim: ts=4 sw=4 expandtab
import os
+import unittest
import warnings
+def _getwarningsconf():
+ lines = []
+ for name in sorted(warnings.warnings.keys()):
+ message = warnings.warnings[name]
+ sign = '+'
+ if name == 'block_without_braces':
+ sign = '-'
+ assert len(name) < 29
+ lines.append(sign + name.ljust(29) + '# ' + message)
+ return '\n'.join(lines)
+
+DEFAULT_CONF = """\
+#
+# Configuration File for JavaScript Lint %(version)s
+# Developed by Matthias Miller (http://www.JavaScriptLint.com)
+#
+# This configuration file can be used to lint a collection of scripts, or to enable
+# or disable warnings for scripts that are linted via the command line.
+#
+
+### Warnings
+# Enable or disable warnings based on requirements.
+# Use "+WarningName" to display or "-WarningName" to suppress.
+#
+%(warnings)s
+
+
+### Output format
+# Customize the format of the error message.
+# __FILE__ indicates current file path
+# __FILENAME__ indicates current file name
+# __LINE__ indicates current line
+# __ERROR__ indicates error message
+#
+# Visual Studio syntax (default):
++output-format __FILE__(__LINE__): __ERROR__
+# Alternative syntax:
+#+output-format __FILE__:__LINE__: __ERROR__
+
+
+### Context
+# Show the in-line position of the error.
+# Use "+context" to display or "-context" to suppress.
+#
++context
+
+
+### Control Comments
+# Both JavaScript Lint and the JScript interpreter confuse each other with the syntax for
+# the /*@keyword@*/ control comments and JScript conditional comments. (The latter is
+# enabled in JScript with @cc_on@). The /*jsl:keyword*/ syntax is preferred for this reason,
+# although legacy control comments are enabled by default for backward compatibility.
+#
+-legacy_control_comments
+
+
+### Defining identifiers
+# By default, "option explicit" is enabled on a per-file basis.
+# To enable this for all files, use "+always_use_option_explicit"
++always_use_option_explicit
+
+# Define certain identifiers of which the lint is not aware.
+# (Use this in conjunction with the "undeclared identifier" warning.)
+#
+# Common uses for webpages might be:
+#+define window
+#+define document
+
+
+### Files
+# Specify which files to lint
+# Use "+recurse" to enable recursion (disabled by default).
+# To add a set of files, use "+process FileName", "+process Folder\Path\*.js",
+# or "+process Folder\Path\*.htm".
+#
+""" % {
+ 'version': '', # TODO
+ 'warnings': _getwarningsconf(),
+}
+
+
class ConfError(Exception):
def __init__(self, error):
Exception.__init__(self, error)
@@ -13,6 +95,12 @@
wants_parm = False
wants_dir = False
+class DeprecatedSetting(Setting):
+ wants_parm = False
+ value = None
+ def load(self, enabled):
+ raise ConfError, 'This setting is deprecated.'
+
class BooleanSetting(Setting):
wants_parm = False
def __init__(self, default):
@@ -54,14 +142,13 @@
recurse = BooleanSetting(False)
self._settings = {
'recurse': recurse,
- 'show_context': BooleanSetting(False),
'output-format': StringSetting('__FILE__(__LINE__): __ERROR__'),
- 'lambda_assign_requires_semicolon': BooleanSetting(False),
- 'legacy_control_comments': BooleanSetting(True),
- 'jscript_function_extensions': BooleanSetting(False),
- 'always_use_option_explicit': BooleanSetting(False),
+ 'lambda_assign_requires_semicolon': DeprecatedSetting(),
+ 'legacy_control_comments': BooleanSetting(False),
+ 'jscript_function_extensions': DeprecatedSetting(),
+ 'always_use_option_explicit': BooleanSetting(True),
'define': DeclareSetting(),
- 'context': BooleanSetting(False),
+ 'context': BooleanSetting(True),
'process': ProcessSetting(recurse),
# SpiderMonkey warnings
'no_return_value': BooleanSetting(True),
@@ -134,3 +221,14 @@
name = 'define'
return self._settings[name].value
+class TestConf(unittest.TestCase):
+ def testDefaultConf(self):
+ # Make sure the string version corresponds with the code.
+ fromstr = Conf()
+ fromstr.loadtext(DEFAULT_CONF)
+ fromcode = Conf()
+ settings = set(fromcode._settings.keys() + fromstr._settings.keys())
+ for setting in settings:
+ self.assertEquals(fromcode[setting], fromstr[setting],
+ 'Mismatched defaults for %s' % setting)
+
Modified: trunk/javascriptlint/jsl.py
===================================================================
--- trunk/javascriptlint/jsl.py 2009-10-03 17:39:40 UTC (rev 257)
+++ trunk/javascriptlint/jsl.py 2009-10-03 18:10:05 UTC (rev 258)
@@ -81,6 +81,8 @@
help="minimal output")
add("--verbose", dest="verbosity", action="store_const", const=2,
help="verbose output")
+ add("--help:conf", dest="showdefaultconf", action="store_true", default=False,
+ help="display the default configuration file")
parser.set_defaults(verbosity=1)
options, args = parser.parse_args()
@@ -88,6 +90,10 @@
parser.print_help()
sys.exit()
+ if options.showdefaultconf:
+ print conf.DEFAULT_CONF
+ sys.exit()
+
conf_ = conf.Conf()
if options.conf:
conf_.loadfile(options.conf)
@@ -98,7 +104,7 @@
if options.unittest:
suite = unittest.TestSuite();
- for module in [htmlparse, jsparse, util]:
+ for module in [conf, htmlparse, jsparse, util]:
suite.addTest(unittest.findTestCases(module))
runner = unittest.TextTestRunner(verbosity=options.verbosity)
Modified: trunk/javascriptlint/warnings.py
===================================================================
--- trunk/javascriptlint/warnings.py 2009-10-03 17:39:40 UTC (rev 257)
+++ trunk/javascriptlint/warnings.py 2009-10-03 18:10:05 UTC (rev 258)
@@ -82,7 +82,7 @@
'nested_comment': 'nested comment',
'legacy_cc_not_understood': 'couldn\'t understand control comment using /*@keyword@*/ syntax',
'var_hides_arg': 'variable {name} hides argument',
- 'duplicate_formal': 'TODO',
+ 'duplicate_formal': 'duplicate formal argument {name}',
'missing_semicolon': 'missing semicolon',
'missing_semicolon_for_lambda': 'missing semicolon for lambda assignment',
'ambiguous_newline': 'unexpected end of line; it is ambiguous whether these lines are part of the same statement',
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|