[javascriptlint-commit] SF.net SVN: javascriptlint:[215] trunk
Status: Beta
Brought to you by:
matthiasmiller
From: <mat...@us...> - 2008-08-24 00:37:06
|
Revision: 215 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=215&view=rev Author: matthiasmiller Date: 2008-08-24 00:37:04 +0000 (Sun, 24 Aug 2008) Log Message: ----------- useless_quotes: only warn if the text would be syntactically valid Modified Paths: -------------- trunk/jsl.py trunk/pyjsl/lint.py trunk/pyjsl/util.py trunk/pyjsl/warnings.py trunk/tests/warnings/ambiguous_newline.js Modified: trunk/jsl.py =================================================================== --- trunk/jsl.py 2008-08-23 23:58:12 UTC (rev 214) +++ trunk/jsl.py 2008-08-24 00:37:04 UTC (rev 215) @@ -129,8 +129,12 @@ profile_func = profile_enabled if options.unittest: + suite = unittest.TestSuite(); + for module in [pyjsl.jsparse, pyjsl.util]: + suite.addTest(unittest.findTestCases(module)) + runner = unittest.TextTestRunner(verbosity=options.verbosity) - runner.run(unittest.findTestCases(pyjsl.jsparse)) + runner.run(suite) if options.test: profile_func(run_tests) Modified: trunk/pyjsl/lint.py =================================================================== --- trunk/pyjsl/lint.py 2008-08-23 23:58:12 UTC (rev 214) +++ trunk/pyjsl/lint.py 2008-08-24 00:37:04 UTC (rev 215) @@ -29,8 +29,6 @@ 'arguments', 'undefined' ]) -_identifier = re.compile('^[A-Za-z_$][A-Za-z0-9_$]*$') - def _find_function(node): while node and node.kind != tok.FUNCTION: node = node.parent @@ -222,7 +220,7 @@ if cc: node, keyword, parms = cc if keyword == 'declare': - if not _identifier.match(parms): + if not util.isidentifier(parms): report(node, 'jsl_cc_not_understood') else: declares.append((parms, node)) Modified: trunk/pyjsl/util.py =================================================================== --- trunk/pyjsl/util.py 2008-08-23 23:58:12 UTC (rev 214) +++ trunk/pyjsl/util.py 2008-08-24 00:37:04 UTC (rev 215) @@ -1,7 +1,14 @@ # vim: ts=4 sw=4 expandtab import codecs import os.path +import re +import unittest +_identifier = re.compile('^[A-Za-z_$][A-Za-z0-9_$]*$') + +def isidentifier(text): + return _identifier.match(text) + def readfile(path): file = codecs.open(path, 'r', 'utf-8') contents = file.read() @@ -15,3 +22,14 @@ path = os.path.normpath(path) return path +class TestUtil(unittest.TestCase): + def testIdentifier(self): + assert not isidentifier('') + assert not isidentifier('0a') + assert not isidentifier('a b') + assert isidentifier('a') + assert isidentifier('$0') + +if __name__ == '__main__': + unittest.main() + Modified: trunk/pyjsl/warnings.py =================================================================== --- trunk/pyjsl/warnings.py 2008-08-23 23:58:12 UTC (rev 214) +++ trunk/pyjsl/warnings.py 2008-08-24 00:37:04 UTC (rev 215) @@ -18,6 +18,7 @@ import sys import types +import util import visitation from pyspidermonkey import tok, op @@ -420,7 +421,9 @@ @lookfor(tok.STRING) def useless_quotes(node): if node.node_index == 0 and node.parent.kind == tok.COLON: - raise LintWarning, node + # Only warn if the quotes could safely be removed. + if util.isidentifier(node.atom): + raise LintWarning, node @lookfor() def mismatch_ctrl_comments(node): Modified: trunk/tests/warnings/ambiguous_newline.js =================================================================== --- trunk/tests/warnings/ambiguous_newline.js 2008-08-23 23:58:12 UTC (rev 214) +++ trunk/tests/warnings/ambiguous_newline.js 2008-08-24 00:37:04 UTC (rev 215) @@ -185,8 +185,8 @@ /* legal */ o = { - 'one': 1, - 'two': 2 + one: 1, + two: 2 }; /* legal */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |