Thread: [javascriptlint-commit] SF.net SVN: javascriptlint:[344] trunk (Page 4)
Status: Beta
Brought to you by:
matthiasmiller
|
From: <mat...@us...> - 2013-10-10 15:24:22
|
Revision: 344
http://sourceforge.net/p/javascriptlint/code/344
Author: matthiasmiller
Date: 2013-10-10 15:24:17 +0000 (Thu, 10 Oct 2013)
Log Message:
-----------
Run jsengine unit tests and fix broken tests.
Modified Paths:
--------------
trunk/javascriptlint/jsl.py
trunk/jsengine/parser/__init__.py
Modified: trunk/javascriptlint/jsl.py
===================================================================
--- trunk/javascriptlint/jsl.py 2013-10-10 14:07:41 UTC (rev 343)
+++ trunk/javascriptlint/jsl.py 2013-10-10 15:24:17 UTC (rev 344)
@@ -12,6 +12,7 @@
import fs
import htmlparse
import jsparse
+import jsengine.parser
import lint
import util
import version
@@ -123,7 +124,7 @@
if options.unittest:
suite = unittest.TestSuite();
- for module in [conf, htmlparse, jsparse, lint, util]:
+ for module in [conf, htmlparse, jsengine.parser, jsparse, lint, util]:
suite.addTest(unittest.findTestCases(module))
runner = unittest.TextTestRunner(verbosity=options.verbosity)
Modified: trunk/jsengine/parser/__init__.py
===================================================================
--- trunk/jsengine/parser/__init__.py 2013-10-10 14:07:41 UTC (rev 343)
+++ trunk/jsengine/parser/__init__.py 2013-10-10 15:24:17 UTC (rev 344)
@@ -854,7 +854,7 @@
try:
parsestring('/*')
except JSSyntaxError as error:
- self.assertEqual(error.pos, NodePos(0, 1))
+ self.assertEqual(error.offset, 1)
else:
self.assert_(False)
def testObjectEndComma(self):
@@ -867,9 +867,9 @@
self.assertEquals(left.atom, 'a')
self.assertEquals(right.kind, kind.RC)
node = right.end_comma
- self.assertEquals(node.kind, tok.COMMA)
- self.assertEquals(node.start_offset, NodePos(0, 6))
- self.assertEquals(node.end_offset, NodePos(0, 6))
+ self.assertEquals(node.kind, kind.COMMA)
+ self.assertEquals(node.start_offset, 6)
+ self.assertEquals(node.end_offset, 6)
def _testArrayEndComma(self, script, col):
root = parsestring(script)
node, = root.kids
@@ -884,9 +884,9 @@
if col is None:
self.assert_(node is None)
else:
- self.assertEquals(node.kind, tok.COMMA)
- self.assertEquals(node.start_offset, NodePos(0, col))
- self.assertEquals(node.end_offset, NodePos(0, col))
+ self.assertEquals(node.kind, kind.COMMA)
+ self.assertEquals(node.start_offset, col)
+ self.assertEquals(node.end_offset, col)
def testArrayEndComma(self):
self._testArrayEndComma('a=[,]', 3)
self._testArrayEndComma('a=[a,]', 4)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2013-12-07 16:32:57
|
Revision: 347
http://sourceforge.net/p/javascriptlint/code/347
Author: matthiasmiller
Date: 2013-12-07 16:32:54 +0000 (Sat, 07 Dec 2013)
Log Message:
-----------
#46 Function name mismatch warning when assigning to property
Apply attached patched.
Modified Paths:
--------------
trunk/javascriptlint/warnings.py
trunk/tests/warnings/function_name_mismatch.js
trunk/tests/warnings/function_name_missing.js
Modified: trunk/javascriptlint/warnings.py
===================================================================
--- trunk/javascriptlint/warnings.py 2013-10-10 15:28:32 UTC (rev 346)
+++ trunk/javascriptlint/warnings.py 2013-12-07 16:32:54 UTC (rev 347)
@@ -662,6 +662,9 @@
if parent.kids[0].kind == tok.NAME and \
parent.kids[0].opcode == op.SETNAME:
return parent.kids[0].atom
+ if parent.kids[0].kind == tok.DOT and \
+ parent.kids[0].opcode == op.SETPROP:
+ return parent.kids[0].atom
return '<error>'
# Object literal.
Modified: trunk/tests/warnings/function_name_mismatch.js
===================================================================
--- trunk/tests/warnings/function_name_mismatch.js 2013-10-10 15:28:32 UTC (rev 346)
+++ trunk/tests/warnings/function_name_mismatch.js 2013-12-07 16:32:54 UTC (rev 347)
@@ -32,5 +32,14 @@
function x() {
}
+
+ function Class() {
+ }
+ Class.prototype.get = function gt() { /*warning:function_name_mismatch*/
+ return this.value;
+ };
+ Class.prototype.set = function set(value) {
+ this.value = value;
+ };
}
Modified: trunk/tests/warnings/function_name_missing.js
===================================================================
--- trunk/tests/warnings/function_name_missing.js 2013-10-10 15:28:32 UTC (rev 346)
+++ trunk/tests/warnings/function_name_missing.js 2013-12-07 16:32:54 UTC (rev 347)
@@ -26,5 +26,14 @@
function x() {
}
+
+ function Class() {
+ }
+ Class.prototype.get = function () { /*warning:function_name_missing*/
+ return this.value;
+ };
+ Class.prototype.set = function set(value) {
+ this.value = value;
+ };
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2014-01-08 22:59:05
|
Revision: 348
http://sourceforge.net/p/javascriptlint/code/348
Author: matthiasmiller
Date: 2014-01-08 22:59:01 +0000 (Wed, 08 Jan 2014)
Log Message:
-----------
Allow the function_name warnings to require name decoration.
Modified Paths:
--------------
trunk/javascriptlint/conf.py
trunk/javascriptlint/lint.py
trunk/javascriptlint/warnings.py
trunk/tests/warnings/function_name_mismatch.js
trunk/tests/warnings/function_name_missing.js
Added Paths:
-----------
trunk/tests/warnings/function_name_mismatch_decorated.js
Modified: trunk/javascriptlint/conf.py
===================================================================
--- trunk/javascriptlint/conf.py 2013-12-07 16:32:54 UTC (rev 347)
+++ trunk/javascriptlint/conf.py 2014-01-08 22:59:01 UTC (rev 348)
@@ -94,6 +94,12 @@
#+default-type text/javascript;version=1.5
#+default-type text/javascript;e4x=1
+###
+# Some browsers pollute the namespace when using the "function_name_missing"
+# or "function_name_mismatch" warning. Enable this option to require a
+# double-underscore prefix.
+#+decorate_function_name_warning
+
### Files
# Specify which files to lint
# Use "+recurse" to enable recursion (disabled by default).
@@ -186,7 +192,8 @@
# SpiderMonkey warnings
'no_return_value': BooleanSetting(True),
'equal_as_assign': BooleanSetting(True),
- 'anon_no_return_value': BooleanSetting(True)
+ 'anon_no_return_value': BooleanSetting(True),
+ 'decorate_function_name_warning': BooleanSetting(False),
}
for name in warnings.warnings:
self._settings[name] = BooleanSetting(True)
Modified: trunk/javascriptlint/lint.py
===================================================================
--- trunk/javascriptlint/lint.py 2013-12-07 16:32:54 UTC (rev 347)
+++ trunk/javascriptlint/lint.py 2014-01-08 22:59:01 UTC (rev 348)
@@ -482,7 +482,7 @@
# Find all visitors and convert them into "onpush" callbacks that call "report"
visitors = {
- 'push': warnings.make_visitors()
+ 'push': warnings.make_visitors(conf)
}
for event in visitors:
for kind, callbacks in visitors[event].items():
Modified: trunk/javascriptlint/warnings.py
===================================================================
--- trunk/javascriptlint/warnings.py 2013-12-07 16:32:54 UTC (rev 347)
+++ trunk/javascriptlint/warnings.py 2014-01-08 22:59:01 UTC (rev 348)
@@ -139,6 +139,20 @@
_visitors.append((arg, fn))
return decorate
+_visitor_classes = []
+def lookfor_class(*args):
+ def decorate(cls):
+ # Convert the class name to camel case
+ camelcase = re.sub('([A-Z])', r'_\1', cls.__name__).lower().lstrip('_')
+
+ cls.warning = camelcase.rstrip('_')
+ assert cls.warning in warnings, \
+ 'Missing warning description: %s' % cls.warning
+
+ for arg in args:
+ _visitor_classes.append((arg, cls))
+ return decorate
+
class LintWarning(Exception):
def __init__(self, node, **errargs):
self.node = node
@@ -638,7 +652,7 @@
return # Allow as constructors
raise LintWarning(node)
-def _get_expected_function_name(node):
+def _get_function_property_name(node):
# Ignore function statements.
if node.opcode in (None, op.CLOSURE):
return
@@ -671,27 +685,42 @@
if parent.kind == tok.COLON and parent.parent.kind == tok.RC:
return parent.kids[0].atom
-@lookfor(tok.FUNCTION)
-def function_name_missing(node):
- if node.fn_name:
- return
+def _get_expected_function_name(node, decorate):
+ name = _get_function_property_name(node)
+ if name and decorate:
+ return '__%s' % name
+ return name
- expected_name = _get_expected_function_name(node)
- if not expected_name is None:
- raise LintWarning(node, name=expected_name)
+@lookfor_class(tok.FUNCTION)
+class FunctionNameMissing(object):
+ def __init__(self, conf):
+ self._decorate = conf['decorate_function_name_warning']
-@lookfor(tok.FUNCTION)
-def function_name_mismatch(node):
- if not node.fn_name:
- return
+ def __call__(self, node):
+ if node.fn_name:
+ return
- expected_name = _get_expected_function_name(node)
- if expected_name is None:
- return
+ expected_name = _get_expected_function_name(node, self._decorate)
+ if not expected_name is None:
+ raise LintWarning(node, name=expected_name)
- if expected_name != node.fn_name:
- raise LintWarning(node, fn_name=node.fn_name, prop_name=expected_name)
+@lookfor_class(tok.FUNCTION)
+class FunctionNameMismatch(object):
+ def __init__(self, conf):
+ self._decorate = conf['decorate_function_name_warning']
+ def __call__(self, node):
+ if not node.fn_name:
+ return
+
+ expected_name = _get_expected_function_name(node, self._decorate)
+ if expected_name is None:
+ return
+
+ if expected_name != node.fn_name:
+ raise LintWarning(node, fn_name=node.fn_name,
+ prop_name=expected_name)
+
@lookfor()
def mismatch_ctrl_comments(node):
pass
@@ -755,9 +784,13 @@
def dup_option_explicit(node):
pass
-def make_visitors():
+def make_visitors(conf):
+ all_visitors = list(_visitors)
+ for kind, klass in _visitor_classes:
+ all_visitors.append((kind, klass(conf=conf)))
+
visitors = {}
- for kind, func in _visitors:
+ for kind, func in all_visitors:
try:
visitors[kind].append(func)
except KeyError:
Modified: trunk/tests/warnings/function_name_mismatch.js
===================================================================
--- trunk/tests/warnings/function_name_mismatch.js 2013-12-07 16:32:54 UTC (rev 347)
+++ trunk/tests/warnings/function_name_mismatch.js 2014-01-08 22:59:01 UTC (rev 348)
@@ -34,6 +34,12 @@
}
function Class() {
+ this.getStr = function getSt() { /*warning:function_name_mismatch*/
+ return this.str;
+ };
+ this.setStr = function setStr(s) {
+ this.str = s;
+ };
}
Class.prototype.get = function gt() { /*warning:function_name_mismatch*/
return this.value;
Copied: trunk/tests/warnings/function_name_mismatch_decorated.js (from rev 347, trunk/tests/warnings/function_name_mismatch.js)
===================================================================
--- trunk/tests/warnings/function_name_mismatch_decorated.js (rev 0)
+++ trunk/tests/warnings/function_name_mismatch_decorated.js 2014-01-08 22:59:01 UTC (rev 348)
@@ -0,0 +1,32 @@
+/*conf:+function_name_mismatch*/
+/*conf:+decorate_function_name_warning*/
+function function_name_mismatch_decorated() {
+ var f = function bogus() { /*warning:function_name_mismatch*/
+ };
+ var g = function g() { /*warning:function_name_mismatch*/
+ };
+ var h = function __h() {
+ };
+
+ f = new function bogus() {
+ };
+ f = new function() {
+ };
+
+ f = (function() {
+ return 10;
+ })();
+
+ function Class() {
+ }
+ Class.prototype.get = function gt() { /*warning:function_name_mismatch*/
+ return this.value;
+ };
+ Class.prototype.set = function set(value) { /*warning:function_name_mismatch*/
+ this.value = value;
+ };
+ Class.prototype.inc = function __inc(value) {
+ this.value++;
+ };
+}
+
Modified: trunk/tests/warnings/function_name_missing.js
===================================================================
--- trunk/tests/warnings/function_name_missing.js 2013-12-07 16:32:54 UTC (rev 347)
+++ trunk/tests/warnings/function_name_missing.js 2014-01-08 22:59:01 UTC (rev 348)
@@ -28,6 +28,12 @@
}
function Class() {
+ this.getStr = function () { /*warning:function_name_missing*/
+ return this.str;
+ };
+ this.setStr = function setStr(s) {
+ this.str = s;
+ };
}
Class.prototype.get = function () { /*warning:function_name_missing*/
return this.value;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2014-02-10 15:09:25
|
Revision: 349
http://sourceforge.net/p/javascriptlint/code/349
Author: matthiasmiller
Date: 2014-02-10 15:09:21 +0000 (Mon, 10 Feb 2014)
Log Message:
-----------
Fix warning position for trailing commas.
Modified Paths:
--------------
trunk/javascriptlint/warnings.py
trunk/tests/warnings/spidermonkey/trailing_comma.js
trunk/tests/warnings/trailing_comma_in_array.js
Modified: trunk/javascriptlint/warnings.py
===================================================================
--- trunk/javascriptlint/warnings.py 2014-01-08 22:59:01 UTC (rev 348)
+++ trunk/javascriptlint/warnings.py 2014-02-10 15:09:21 UTC (rev 349)
@@ -547,12 +547,17 @@
@lookfor(tok.RC)
def trailing_comma(node):
if node.end_comma:
- raise LintWarning(node)
+ # Warn on the last value in the dictionary.
+ last_item = node.kids[-1]
+ assert last_item.kind == tok.COLON
+ key, value = last_item.kids
+ raise LintWarning(value)
@lookfor(tok.RB)
def trailing_comma_in_array(node):
if node.end_comma:
- raise LintWarning(node)
+ # Warn on the last value in the array.
+ raise LintWarning(node.kids[-1])
@lookfor(tok.STRING)
def useless_quotes(node):
Modified: trunk/tests/warnings/spidermonkey/trailing_comma.js
===================================================================
--- trunk/tests/warnings/spidermonkey/trailing_comma.js 2014-01-08 22:59:01 UTC (rev 348)
+++ trunk/tests/warnings/spidermonkey/trailing_comma.js 2014-02-10 15:09:21 UTC (rev 349)
@@ -1,5 +1,8 @@
/*jsl:option explicit*/
function trailing_comma() {
/* illegal - trailing comma */
- return { name: 'value', }; /*warning:trailing_comma*/
+ return {
+ name:
+ 'value', /*warning:trailing_comma*/
+ };
}
Modified: trunk/tests/warnings/trailing_comma_in_array.js
===================================================================
--- trunk/tests/warnings/trailing_comma_in_array.js 2014-01-08 22:59:01 UTC (rev 348)
+++ trunk/tests/warnings/trailing_comma_in_array.js 2014-02-10 15:09:21 UTC (rev 349)
@@ -5,4 +5,12 @@
a = [1,,2];
a = [1,]; /*warning:trailing_comma_in_array*/
a = [1,,]; /*warning:trailing_comma_in_array*/
+ a = [
+ , /*warning:trailing_comma_in_array*/
+ ];
+ a = [
+ 1,
+ 2,
+ 3, /*warning:trailing_comma_in_array*/
+ ];
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2014-02-10 23:48:17
|
Revision: 350
http://sourceforge.net/p/javascriptlint/code/350
Author: matthiasmiller
Date: 2014-02-10 23:48:14 +0000 (Mon, 10 Feb 2014)
Log Message:
-----------
Fix traceback on expected_tok error.
Modified Paths:
--------------
trunk/javascriptlint/warnings.py
trunk/jsengine/tokenizer/__init__.py
Added Paths:
-----------
trunk/tests/errors/expected_tok.js
Modified: trunk/javascriptlint/warnings.py
===================================================================
--- trunk/javascriptlint/warnings.py 2014-02-10 15:09:21 UTC (rev 349)
+++ trunk/javascriptlint/warnings.py 2014-02-10 23:48:14 UTC (rev 350)
@@ -124,9 +124,10 @@
errdesc = warnings[errname]
try:
- errdesc = re.sub(r"{(\w+)}", lambda match: errargs[match.group(1)], errdesc)
+ keyword = re.compile(r"{(\w+)}")
+ errdesc = keyword.sub(lambda match: errargs[match.group(1)], errdesc)
except (TypeError, KeyError):
- raise KeyError('Invalid keyword in error: ' + errdesc)
+ raise KeyError('Invalid keyword in error %s: %s' % (errname, errdesc))
return errdesc
_visitors = []
Modified: trunk/jsengine/tokenizer/__init__.py
===================================================================
--- trunk/jsengine/tokenizer/__init__.py 2014-02-10 15:09:21 UTC (rev 349)
+++ trunk/jsengine/tokenizer/__init__.py 2014-02-10 23:48:14 UTC (rev 350)
@@ -170,7 +170,7 @@
encountered = self.advance()
if encountered.tok != tok:
raise JSSyntaxError(encountered.start_offset, 'expected_tok',
- { 'token': tok })
+ { 'token': tok.getliteral() })
return encountered
def expect_identifiername(self):
Added: trunk/tests/errors/expected_tok.js
===================================================================
--- trunk/tests/errors/expected_tok.js (rev 0)
+++ trunk/tests/errors/expected_tok.js 2014-02-10 23:48:14 UTC (rev 350)
@@ -0,0 +1,4 @@
+function expected_tok() {
+ return { a, }; /*warning:expected_tok*/
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2014-10-27 19:12:00
|
Revision: 351
http://sourceforge.net/p/javascriptlint/code/351
Author: matthiasmiller
Date: 2014-10-27 19:11:53 +0000 (Mon, 27 Oct 2014)
Log Message:
-----------
Fix incorrect warning about unreachable loop condition.
Modified Paths:
--------------
trunk/javascriptlint/warnings.py
Added Paths:
-----------
trunk/tests/bugs/unreachable_loop_condition.js
Modified: trunk/javascriptlint/warnings.py
===================================================================
--- trunk/javascriptlint/warnings.py 2014-02-10 23:48:14 UTC (rev 350)
+++ trunk/javascriptlint/warnings.py 2014-10-27 19:11:53 UTC (rev 351)
@@ -265,6 +265,14 @@
return exit_points
+def _loop_has_unreachable_condition(node):
+ for exit_point in _get_exit_points(node):
+ if exit_point is None:
+ return False
+ if exit_point.kind == tok.CONTINUE:
+ return False
+ return True
+
@lookfor((tok.EQOP, op.EQ))
def comparison_type_conv(node):
for kid in node.kids:
@@ -493,14 +501,14 @@
if preamble.kind == tok.RESERVED:
pre, condition, post = preamble.kids
if post:
- if not None in _get_exit_points(code):
+ if _loop_has_unreachable_condition(code):
raise LintWarning(post)
@lookfor(tok.DO)
def unreachable_code__(node):
# Warn if the do..while loop always exits.
code, condition = node.kids
- if not None in _get_exit_points(code):
+ if _loop_has_unreachable_condition(code):
raise LintWarning(condition)
#TODO: @lookfor(tok.IF)
Added: trunk/tests/bugs/unreachable_loop_condition.js
===================================================================
--- trunk/tests/bugs/unreachable_loop_condition.js (rev 0)
+++ trunk/tests/bugs/unreachable_loop_condition.js 2014-10-27 19:11:53 UTC (rev 351)
@@ -0,0 +1,36 @@
+function unreachable_loop_condition(skip) {
+ /* continue will run the condition.
+ */
+ for (var i = 0; i < 10; i++) {
+ if (skip)
+ continue;
+ break;
+ }
+
+ for (i = 0; i < 10; i++) { /*warning:unreachable_code*/
+ if (skip)
+ return;
+ break;
+ }
+
+
+ /* test with do..while
+ */
+ i = 0;
+ do {
+ i += 1;
+ if (skip)
+ continue;
+ break;
+ } while(i < 10);
+
+ i = 0;
+ do {
+ i += 1;
+ if (skip)
+ return;
+ break;
+ } while(i < 10); /*warning:unreachable_code*/
+
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2014-10-27 19:43:07
|
Revision: 352
http://sourceforge.net/p/javascriptlint/code/352
Author: matthiasmiller
Date: 2014-10-27 19:42:54 +0000 (Mon, 27 Oct 2014)
Log Message:
-----------
Add trailing_whitespace warning.
Modified Paths:
--------------
trunk/javascriptlint/conf.py
trunk/javascriptlint/jsparse.py
trunk/javascriptlint/lint.py
trunk/javascriptlint/warnings.py
trunk/jsengine/parser/_constants_kind.py
Modified: trunk/javascriptlint/conf.py
===================================================================
--- trunk/javascriptlint/conf.py 2014-10-27 19:11:53 UTC (rev 351)
+++ trunk/javascriptlint/conf.py 2014-10-27 19:42:54 UTC (rev 352)
@@ -11,6 +11,7 @@
'block_without_braces',
'function_name_missing',
'function_name_mismatch',
+ 'trailing_whitespace',
)
def _getwarningsconf():
Modified: trunk/javascriptlint/jsparse.py
===================================================================
--- trunk/javascriptlint/jsparse.py 2014-10-27 19:11:53 UTC (rev 351)
+++ trunk/javascriptlint/jsparse.py 2014-10-27 19:42:54 UTC (rev 352)
@@ -87,6 +87,20 @@
possible_comments = findpossiblecomments(script, start_offset)
return filtercomments(possible_comments, root_node)
+def find_trailing_whitespace(script, script_offset):
+ nodes = []
+
+ trailing_whitespace = re.compile(r'\S(?P<whitespace>[^\S\r\n]+)([\r\n]|$)')
+
+ for match in trailing_whitespace.finditer(script):
+ start = match.start('whitespace')
+ end = match.end('whitespace')
+ nodes.append(ParseNode(kind.WHITESPACE, None,
+ script_offset + start,
+ script_offset + end-1,
+ script[start:end], []))
+ return nodes
+
def is_compilable_unit(script, jsversion):
jsversion = jsversion or JSVersion.default()
assert isvalidversion(jsversion)
@@ -262,7 +276,22 @@
testcomment('%s' % comment, 7, 7)
testcomment(' %s' % comment, 7, 8)
testcomment('\n\n %s' % comment, 7, 10)
+ def testTrailingWhitespace(self):
+ def testwhitespace(text, expected_whitespace):
+ nodes = find_trailing_whitespace(text, 0)
+ if expected_whitespace:
+ node, = nodes
+ self.assertEquals(node.atom, expected_whitespace)
+ else:
+ self.assertEquals(nodes, [])
+ testwhitespace(' ', '')
+ testwhitespace(' \n', '')
+ testwhitespace('a \n', ' ')
+ testwhitespace('a\n ', '')
+ testwhitespace('a\n {} ', ' ')
+ testwhitespace('a\n {} \n', ' ')
+
if __name__ == '__main__':
unittest.main()
Modified: trunk/javascriptlint/lint.py
===================================================================
--- trunk/javascriptlint/lint.py 2014-10-27 19:11:53 UTC (rev 351)
+++ trunk/javascriptlint/lint.py 2014-10-27 19:42:54 UTC (rev 352)
@@ -511,6 +511,9 @@
unused_scope = script_cache.scope.find_scope(node)
unused_scope.set_unused(name, node)
+ for node in jsparse.find_trailing_whitespace(script, script_offset):
+ report(node, 'trailing_whitespace')
+
def _lint_script_parts(script_parts, script_cache, lint_error, conf, import_callback):
def report_lint(node, errname, offset=0, **errargs):
errdesc = warnings.format_error(errname, **errargs)
Modified: trunk/javascriptlint/warnings.py
===================================================================
--- trunk/javascriptlint/warnings.py 2014-10-27 19:11:53 UTC (rev 351)
+++ trunk/javascriptlint/warnings.py 2014-10-27 19:42:54 UTC (rev 352)
@@ -105,6 +105,7 @@
'misplaced_function': 'unconventional use of function expression',
'function_name_missing': 'anonymous function should be named to match property name {name}',
'function_name_mismatch': 'function name {fn_name} does not match property name {prop_name}',
+ 'trailing_whitespace': 'trailing whitespace',
}
errors = {
Modified: trunk/jsengine/parser/_constants_kind.py
===================================================================
--- trunk/jsengine/parser/_constants_kind.py 2014-10-27 19:11:53 UTC (rev 351)
+++ trunk/jsengine/parser/_constants_kind.py 2014-10-27 19:42:54 UTC (rev 352)
@@ -64,6 +64,7 @@
'RB',
'STRING',
'YIELD', # TODO
+ 'WHITESPACE',
]
class _Kind(object):
def __init__(self, name):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2016-12-23 22:31:14
|
Revision: 360
http://sourceforge.net/p/javascriptlint/code/360
Author: matthiasmiller
Date: 2016-12-23 22:31:12 +0000 (Fri, 23 Dec 2016)
Log Message:
-----------
Clean up imports.
Modified Paths:
--------------
trunk/javascriptlint/jsl.py
trunk/javascriptlint/jsparse.py
trunk/javascriptlint/lint.py
trunk/javascriptlint/lintwarnings.py
trunk/jsengine/structs.py
Modified: trunk/javascriptlint/jsl.py
===================================================================
--- trunk/javascriptlint/jsl.py 2016-12-23 22:27:20 UTC (rev 359)
+++ trunk/javascriptlint/jsl.py 2016-12-23 22:31:12 UTC (rev 360)
@@ -1,9 +1,7 @@
#!/usr/bin/python
# vim: ts=4 sw=4 expandtab
-import codecs
import fnmatch
import functools
-import glob
import os
import sys
import unittest
Modified: trunk/javascriptlint/jsparse.py
===================================================================
--- trunk/javascriptlint/jsparse.py 2016-12-23 22:27:20 UTC (rev 359)
+++ trunk/javascriptlint/jsparse.py 2016-12-23 22:31:12 UTC (rev 360)
@@ -42,7 +42,7 @@
start_offset = match.start()
end_offset = match.end()-1
- comment_node = ParseNode(kind.COMMENT, opcode,
+ comment_node = ParseNode(tok.COMMENT, opcode,
script_offset + start_offset,
script_offset + end_offset, comment_text, [])
comments.append(comment_node)
@@ -95,7 +95,7 @@
for match in trailing_whitespace.finditer(script):
start = match.start('whitespace')
end = match.end('whitespace')
- nodes.append(ParseNode(kind.WHITESPACE, None,
+ nodes.append(ParseNode(tok.WHITESPACE, None,
script_offset + start,
script_offset + end-1,
script[start:end], []))
Modified: trunk/javascriptlint/lint.py
===================================================================
--- trunk/javascriptlint/lint.py 2016-12-23 22:27:20 UTC (rev 359)
+++ trunk/javascriptlint/lint.py 2016-12-23 22:31:12 UTC (rev 360)
@@ -1,7 +1,6 @@
#!/usr/bin/python
# vim: ts=4 sw=4 expandtab
import os.path
-import re
import conf
import fs
Modified: trunk/javascriptlint/lintwarnings.py
===================================================================
--- trunk/javascriptlint/lintwarnings.py 2016-12-23 22:27:20 UTC (rev 359)
+++ trunk/javascriptlint/lintwarnings.py 2016-12-23 22:31:12 UTC (rev 360)
@@ -16,8 +16,6 @@
"""
import itertools
import re
-import sys
-import types
import util
Modified: trunk/jsengine/structs.py
===================================================================
--- trunk/jsengine/structs.py 2016-12-23 22:27:20 UTC (rev 359)
+++ trunk/jsengine/structs.py 2016-12-23 22:31:12 UTC (rev 360)
@@ -5,6 +5,8 @@
from parser._constants_kind import kind
from parser._constants_op import op
+__all__ = ['NodePositions', 'NodePos', 'NodeRanges', 'ParseNode']
+
class NodePositions:
" Given a string, allows [x] lookups for NodePos line and column numbers."
def __init__(self, text, start_pos=None):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2016-12-23 23:55:20
|
Revision: 365
http://sourceforge.net/p/javascriptlint/code/365
Author: matthiasmiller
Date: 2016-12-23 23:55:18 +0000 (Fri, 23 Dec 2016)
Log Message:
-----------
Use exceptions instead of a callback for parse errors.
Modified Paths:
--------------
trunk/javascriptlint/jsparse.py
trunk/javascriptlint/lint.py
trunk/jsengine/parser/__init__.py
Modified: trunk/javascriptlint/jsparse.py
===================================================================
--- trunk/javascriptlint/jsparse.py 2016-12-23 23:46:55 UTC (rev 364)
+++ trunk/javascriptlint/jsparse.py 2016-12-23 23:55:18 UTC (rev 365)
@@ -4,6 +4,7 @@
import re
import unittest
+from jsengine import JSSyntaxError
import jsengine.parser
from jsengine.parser import kind as tok
from jsengine.parser import op
@@ -51,15 +52,14 @@
# this one was within a string or a regexp.
pos = match.start()+1
-def parse(script, jsversion, error_callback, start_offset=0):
+def parse(script, jsversion, start_offset=0):
""" All node positions will be relative to start_offset. This allows
scripts to be embedded in a file (for example, HTML).
"""
assert not start_offset is None
jsversion = jsversion or JSVersion.default()
assert isvalidversion(jsversion), jsversion
- return jsengine.parser.parse(script, jsversion.version,
- error_callback, start_offset)
+ return jsengine.parser.parse(script, jsversion.version, start_offset)
def filtercomments(possible_comments, root_node):
comment_ignore_ranges = NodeRanges()
@@ -126,15 +126,18 @@
_dump_node(node, node_positions, depth+1)
def dump_tree(script):
- def error_callback(line, col, msg, msg_args):
- print '(%i, %i): %s', (line, col, msg)
- node = parse(script, None, error_callback)
node_positions = NodePositions(script)
+ try:
+ node = parse(script, None)
+ except JSSyntaxError, error:
+ pos = node_positions.from_offset(error.offset)
+ print 'Line %i, Column %i: %s' % (pos.line+1, pos.col+1, error.msg)
+ return
_dump_node(node, node_positions)
class TestComments(unittest.TestCase):
def _test(self, script, expected_comments):
- root = parse(script, None, lambda line, col, msg: None)
+ root = parse(script, None)
comments = findcomments(script, root)
encountered_comments = [node.atom for node in comments]
self.assertEquals(encountered_comments, list(expected_comments))
@@ -239,19 +242,18 @@
class TestLineOffset(unittest.TestCase):
def testErrorPos(self):
def geterror(script, start_offset):
- errors = []
- def onerror(offset, msg, msg_args):
- errors.append((offset, msg, msg_args))
- parse(script, None, onerror, start_offset)
- self.assertEquals(len(errors), 1)
- return errors[0]
+ try:
+ parse(script, None, start_offset)
+ except JSSyntaxError, error:
+ return (error.offset, error.msg, error.msg_args)
+ assert False
self.assertEquals(geterror(' ?', 0), (1, 'syntax_error', {}))
self.assertEquals(geterror('\n ?', 0), (2, 'syntax_error', {}))
self.assertEquals(geterror(' ?', 2), (3, 'syntax_error', {}))
self.assertEquals(geterror('\n ?', 2), (4, 'syntax_error', {}))
def testNodePos(self):
def getnodepos(script, start_offset):
- root = parse(script, None, None, start_offset)
+ root = parse(script, None, start_offset)
self.assertEquals(root.kind, tok.LC)
var, = root.kids
self.assertEquals(var.kind, tok.VAR)
@@ -264,7 +266,7 @@
self.assertEquals(getnodepos('\n\n var x;', 7), 10)
def testComments(self):
def testcomment(comment, startpos, expected_offset):
- root = parse(comment, None, None, startpos)
+ root = parse(comment, None, startpos)
comment, = findcomments(comment, root, startpos)
self.assertEquals(comment.start_offset, expected_offset)
for comment in ('/*comment*/', '//comment'):
Modified: trunk/javascriptlint/lint.py
===================================================================
--- trunk/javascriptlint/lint.py 2016-12-23 23:46:55 UTC (rev 364)
+++ trunk/javascriptlint/lint.py 2016-12-23 23:55:18 UTC (rev 365)
@@ -351,9 +351,6 @@
def _lint_script_part(script_offset, jsversion, script, script_cache, conf,
report_parse_error, report_lint, import_callback):
- def parse_error(offset, msg, msg_args):
- parse_errors.append((offset, msg, msg_args))
-
def report(node, errname, offset=0, **errargs):
if errname == 'empty_statement' and node.kind == tok.LC:
for pass_ in passes:
@@ -387,7 +384,6 @@
report_lint(node, errname, offset, **errargs)
- parse_errors = []
declares = []
unused_identifiers = []
import_paths = []
@@ -421,11 +417,11 @@
report_lint(None, 'e4x_deprecated',
jsversionnode.start_offset if jsversionnode else script_offset)
- root = jsparse.parse(script, jsversion, parse_error, script_offset)
- if not root:
+ try:
+ root = jsparse.parse(script, jsversion, script_offset)
+ except jsparse.JSSyntaxError, error:
# Report errors and quit.
- for offset, msg, msg_args in parse_errors:
- report_parse_error(offset, msg, msg_args)
+ report_parse_error(error.offset, error.msg, error.msg_args)
return
comments = jsparse.filtercomments(possible_comments, root)
@@ -487,10 +483,6 @@
if start_ignore:
report(start_ignore, 'mismatch_ctrl_comments')
- # Wait to report parse errors until loading jsl:ignore directives.
- for offset, msg in parse_errors:
- report_parse_error(offset, msg)
-
# Find all visitors and convert them into "onpush" callbacks that call "report"
visitors = {
'push': lintwarnings.make_visitors(conf)
Modified: trunk/jsengine/parser/__init__.py
===================================================================
--- trunk/jsengine/parser/__init__.py 2016-12-23 23:46:55 UTC (rev 364)
+++ trunk/jsengine/parser/__init__.py 2016-12-23 23:55:18 UTC (rev 365)
@@ -814,7 +814,9 @@
nodes = _sourceelements(t, tok.EOF)
lc_end_offset = t.expect(tok.EOF).end_offset
lc_start_offset = nodes[-1].start_offset if nodes else lc_end_offset
- return ParseNode(kind.LC, None, lc_start_offset, lc_end_offset, None, nodes)
+ root = ParseNode(kind.LC, None, lc_start_offset, lc_end_offset, None, nodes)
+ _validate(root)
+ return root
def is_valid_version(version):
return version in _VERSIONS
@@ -825,16 +827,10 @@
assert kid.parent is node
_validate(kid, depth+1)
-def parse(script, jsversion, error_callback, start_offset):
+def parse(script, jsversion, start_offset):
# TODO: respect version
assert is_valid_version(jsversion)
- try:
- root = parsestring(script, start_offset)
- except JSSyntaxError as error:
- error_callback(error.offset, error.msg, error.msg_args)
- return None
- _validate(root)
- return root
+ return parsestring(script, start_offset)
def is_compilable_unit(script, jsversion):
# TODO: respect version
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2016-12-29 21:50:29
|
Revision: 368
http://sourceforge.net/p/javascriptlint/code/368
Author: matthiasmiller
Date: 2016-12-29 21:50:27 +0000 (Thu, 29 Dec 2016)
Log Message:
-----------
Add warning against duplicate properties in object initializers
Modified Paths:
--------------
trunk/javascriptlint/lintwarnings.py
trunk/tests/warnings/ambiguous_numeric_prop.js
Added Paths:
-----------
trunk/tests/warnings/duplicate_property.js
Modified: trunk/javascriptlint/lintwarnings.py
===================================================================
--- trunk/javascriptlint/lintwarnings.py 2016-12-29 21:46:51 UTC (rev 367)
+++ trunk/javascriptlint/lintwarnings.py 2016-12-29 21:50:27 UTC (rev 368)
@@ -105,6 +105,7 @@
'trailing_whitespace': 'trailing whitespace',
'e4x_deprecated': 'e4x is deprecated',
'ambiguous_numeric_prop': 'numeric property should be normalized; use {normalized}',
+ 'duplicate_property': 'duplicate property in object initializer',
}
errors = {
@@ -635,20 +636,47 @@
if not left.kind in (tok.VAR, tok.NAME):
raise LintWarning(left)
-@lookfor(tok.NUMBER)
-def ambiguous_numeric_prop(node):
+def _normalized_number(node):
+ assert node.kind == tok.NUMBER
if node.atom.startswith('0x'):
value = int(node.atom, 16)
else:
value = float(node.atom)
if value.is_integer():
value = int(value)
+ return str(value)
+@lookfor(tok.NUMBER)
+def ambiguous_numeric_prop(node):
+ normalized = _normalized_number(node)
if (node.node_index == 0 and node.parent.kind == tok.COLON) or \
(node.node_index == 1 and node.parent.kind == tok.LB):
- if str(value) != node.atom:
- raise LintWarning(node, normalized=str(value))
+ if normalized != node.atom:
+ raise LintWarning(node, normalized=normalized)
+def _object_property(node):
+ assert node.kind == tok.COLON
+
+ left, right = node.kids
+ while left.kind == tok.RP:
+ left, = left.kids
+ if left.kind == tok.NUMBER:
+ return _normalized_number(left)
+
+ assert left.kind in (tok.STRING, tok.NAME)
+ return left.atom
+
+@lookfor(tok.COLON)
+def duplicate_property(node):
+ if not node.parent.kind == tok.RC:
+ return
+
+ node_value = _object_property(node)
+ for sibling in node.parent.kids[:node.node_index]:
+ sibling_value = _object_property(sibling)
+ if node_value == sibling_value:
+ raise LintWarning(node)
+
@lookfor(tok.FUNCTION)
def misplaced_function(node):
# Ignore function statements.
Modified: trunk/tests/warnings/ambiguous_numeric_prop.js
===================================================================
--- trunk/tests/warnings/ambiguous_numeric_prop.js 2016-12-29 21:46:51 UTC (rev 367)
+++ trunk/tests/warnings/ambiguous_numeric_prop.js 2016-12-29 21:50:27 UTC (rev 368)
@@ -1,3 +1,4 @@
+/*conf:-duplicate_property*/
function ambiguous_numeric_prop() {
var a = {
1: '',
Added: trunk/tests/warnings/duplicate_property.js
===================================================================
--- trunk/tests/warnings/duplicate_property.js (rev 0)
+++ trunk/tests/warnings/duplicate_property.js 2016-12-29 21:50:27 UTC (rev 368)
@@ -0,0 +1,13 @@
+/*conf:-useless_quotes*/
+/*conf:-ambiguous_numeric_prop*/
+function duplicate_property() {
+ var o = {
+ a: '',
+ "a": '', /*warning:duplicate_property*/
+ 2.00: '',
+ 2: '', /*warning:duplicate_property*/
+ 3.00: '',
+ '3': '', /*warning:duplicate_property*/
+ 'other': ''
+ };
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2016-12-29 21:57:55
|
Revision: 369
http://sourceforge.net/p/javascriptlint/code/369
Author: matthiasmiller
Date: 2016-12-29 21:57:52 +0000 (Thu, 29 Dec 2016)
Log Message:
-----------
Improve error location for trailing comma error.
Modified Paths:
--------------
trunk/javascriptlint/lint.py
trunk/tests/warnings/trailing_comma_in_array.js
Added Paths:
-----------
trunk/tests/warnings/trailing_comma.js
Modified: trunk/javascriptlint/lint.py
===================================================================
--- trunk/javascriptlint/lint.py 2016-12-29 21:50:27 UTC (rev 368)
+++ trunk/javascriptlint/lint.py 2016-12-29 21:57:52 UTC (rev 369)
@@ -556,7 +556,8 @@
except lintwarnings.LintWarning, warning:
# TODO: This is ugly hardcoding to improve the error positioning of
# "missing_semicolon" errors.
- if visitor.warning in ('missing_semicolon', 'missing_semicolon_for_lambda'):
+ if visitor.warning in ('missing_semicolon', 'missing_semicolon_for_lambda',
+ 'trailing_comma', 'trailing_comma_in_array'):
offset = warning.node.end_offset
else:
offset = None
Added: trunk/tests/warnings/trailing_comma.js
===================================================================
--- trunk/tests/warnings/trailing_comma.js (rev 0)
+++ trunk/tests/warnings/trailing_comma.js 2016-12-29 21:57:52 UTC (rev 369)
@@ -0,0 +1,7 @@
+function trailing_comma() {
+ var o = {
+ outer: {
+ inner: 1
+ }, /*warning:trailing_comma*/
+ };
+}
Modified: trunk/tests/warnings/trailing_comma_in_array.js
===================================================================
--- trunk/tests/warnings/trailing_comma_in_array.js 2016-12-29 21:50:27 UTC (rev 368)
+++ trunk/tests/warnings/trailing_comma_in_array.js 2016-12-29 21:57:52 UTC (rev 369)
@@ -13,4 +13,9 @@
2,
3, /*warning:trailing_comma_in_array*/
];
+ a = [
+ {
+ prop: 1
+ }, /*warning:trailing_comma_in_array*/
+ ];
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2016-12-29 22:10:21
|
Revision: 370
http://sourceforge.net/p/javascriptlint/code/370
Author: matthiasmiller
Date: 2016-12-29 22:10:19 +0000 (Thu, 29 Dec 2016)
Log Message:
-----------
Refactor property name functions into utility module.
Modified Paths:
--------------
trunk/javascriptlint/lintwarnings.py
Added Paths:
-----------
trunk/jsengine/js_util.py
Modified: trunk/javascriptlint/lintwarnings.py
===================================================================
--- trunk/javascriptlint/lintwarnings.py 2016-12-29 21:57:52 UTC (rev 369)
+++ trunk/javascriptlint/lintwarnings.py 2016-12-29 22:10:19 UTC (rev 370)
@@ -19,6 +19,7 @@
import util
+from jsengine import js_util
from jsengine.parser import kind as tok
from jsengine.parser import op
@@ -636,44 +637,22 @@
if not left.kind in (tok.VAR, tok.NAME):
raise LintWarning(left)
-def _normalized_number(node):
- assert node.kind == tok.NUMBER
- if node.atom.startswith('0x'):
- value = int(node.atom, 16)
- else:
- value = float(node.atom)
- if value.is_integer():
- value = int(value)
- return str(value)
-
@lookfor(tok.NUMBER)
def ambiguous_numeric_prop(node):
- normalized = _normalized_number(node)
+ normalized = js_util.numeric_property_str(node)
if (node.node_index == 0 and node.parent.kind == tok.COLON) or \
(node.node_index == 1 and node.parent.kind == tok.LB):
if normalized != node.atom:
raise LintWarning(node, normalized=normalized)
-def _object_property(node):
- assert node.kind == tok.COLON
-
- left, right = node.kids
- while left.kind == tok.RP:
- left, = left.kids
- if left.kind == tok.NUMBER:
- return _normalized_number(left)
-
- assert left.kind in (tok.STRING, tok.NAME)
- return left.atom
-
@lookfor(tok.COLON)
def duplicate_property(node):
if not node.parent.kind == tok.RC:
return
- node_value = _object_property(node)
+ node_value = js_util.object_property_str(node)
for sibling in node.parent.kids[:node.node_index]:
- sibling_value = _object_property(sibling)
+ sibling_value = js_util.object_property_str(sibling)
if node_value == sibling_value:
raise LintWarning(node)
Added: trunk/jsengine/js_util.py
===================================================================
--- trunk/jsengine/js_util.py (rev 0)
+++ trunk/jsengine/js_util.py 2016-12-29 22:10:19 UTC (rev 370)
@@ -0,0 +1,25 @@
+# vim: ts=4 sw=4 expandtab
+from parser import kind as tok
+
+def numeric_property_str(node):
+ assert node.kind == tok.NUMBER
+ if node.atom.startswith('0x'):
+ value = int(node.atom, 16)
+ else:
+ value = float(node.atom)
+ if value.is_integer():
+ value = int(value)
+ return str(value)
+
+def object_property_str(node):
+ assert node.kind == tok.COLON
+
+ left, right = node.kids
+ while left.kind == tok.RP:
+ left, = left.kids
+ if left.kind == tok.NUMBER:
+ return numeric_property_str(left)
+
+ assert left.kind in (tok.STRING, tok.NAME)
+ return left.atom
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2016-12-30 22:48:35
|
Revision: 371
http://sourceforge.net/p/javascriptlint/code/371
Author: matthiasmiller
Date: 2016-12-30 22:48:30 +0000 (Fri, 30 Dec 2016)
Log Message:
-----------
Properly distinguish between errors and warnings.
Modified Paths:
--------------
trunk/javascriptlint/jsl.py
trunk/javascriptlint/lint.py
trunk/test.py
trunk/tests/conf/jscript_function_extensions-3.js
trunk/tests/conf/jscript_function_extensions-4.js
trunk/tests/control_comments/conf-version-2.js
trunk/tests/control_comments/conf-version.js
trunk/tests/errors/expected_tok.js
trunk/tests/errors/syntax_error.js
trunk/tests/html/e4x.html
Modified: trunk/javascriptlint/jsl.py
===================================================================
--- trunk/javascriptlint/jsl.py 2016-12-29 22:10:19 UTC (rev 370)
+++ trunk/javascriptlint/jsl.py 2016-12-30 22:48:30 UTC (rev 371)
@@ -17,7 +17,7 @@
import version
_lint_results = {
- 'warnings': 0,
+ 'warning': 0,
'errors': 0
}
@@ -26,8 +26,9 @@
script = fs.readfile(path, encoding)
jsparse.dump_tree(script)
-def _lint_warning(conf_, path, line, col, errname, errdesc):
- _lint_results['warnings'] = _lint_results['warnings'] + 1
+def _lint_warning(conf_, path, line, col, msg_type, errname, errdesc):
+ assert msg_type in ('warning', 'error')
+ _lint_results[msg_type] += 1
print util.format_error(conf_['output-format'], path, line, col,
errname, errdesc)
@@ -120,7 +121,7 @@
try:
conf_.loadfile(options.conf)
except conf.ConfError, error:
- _lint_warning(conf_, error.path, error.lineno, 0, 'conf_error',
+ _lint_warning(conf_, error.path, error.lineno, 0, 'error', 'conf_error',
unicode(error))
profile_func = _profile_disabled
@@ -151,12 +152,12 @@
profile_func(_lint, paths, conf_, options.printlisting, options.encoding)
if options.printsummary:
- print '\n%i error(s), %i warnings(s)' % (_lint_results['errors'],
- _lint_results['warnings'])
+ print '\n%i error(s), %i warnings(s)' % (_lint_results['error'],
+ _lint_results['warning'])
- if _lint_results['errors']:
+ if _lint_results['error']:
sys.exit(3)
- if _lint_results['warnings']:
+ if _lint_results['warning']:
sys.exit(1)
sys.exit(0)
Modified: trunk/javascriptlint/lint.py
===================================================================
--- trunk/javascriptlint/lint.py 2016-12-29 22:10:19 UTC (rev 370)
+++ trunk/javascriptlint/lint.py 2016-12-30 22:48:30 UTC (rev 371)
@@ -288,18 +288,18 @@
def report_lint(node, errname, offset=0, **errargs):
assert errname in lintwarnings.warnings, errname
if conf[errname]:
- _report(offset or node.start_offset, errname, errargs)
+ _report(offset or node.start_offset, 'warning', errname, errargs)
def report_parse_error(offset, errname, errargs):
assert errname in lintwarnings.errors, errname
- _report(offset, errname, errargs)
+ _report(offset, 'error', errname, errargs)
- def _report(offset, errname, errargs):
+ def _report(offset, msg_type, errname, errargs):
errdesc = lintwarnings.format_error(errname, **errargs)
if lint_cache[normpath].should_ignore(offset):
return
pos = node_positions.from_offset(offset)
- return lint_error(normpath, pos.line, pos.col, errname, errdesc)
+ return lint_error(normpath, pos.line, pos.col, msg_type, errname, errdesc)
normpath = fs.normpath(path)
if normpath in lint_cache:
Modified: trunk/test.py
===================================================================
--- trunk/test.py 2016-12-29 22:10:19 UTC (rev 370)
+++ trunk/test.py 2016-12-30 22:48:30 UTC (rev 371)
@@ -33,15 +33,15 @@
"returns an array of tuples -- line, warning"
warnings = []
- regexp = re.compile(r"/\*warning:([^*]*)\*/")
+ regexp = re.compile(r"/\*(error|warning):([^*]*)\*/")
lines = script.splitlines()
for i in range(0, len(lines)):
- for warning in regexp.findall(lines[i]):
+ for msg_type, warning in regexp.findall(lines[i]):
# TODO: implement these
unimpl_warnings = ('dup_option_explicit',)
if not warning in unimpl_warnings:
- warnings.append((i, warning))
+ warnings.append((i, msg_type, warning))
return warnings
def _testfile(path):
@@ -51,13 +51,13 @@
unexpected_warnings = []
conf = _get_conf(script)
- def lint_error(path, line, col, errname, errdesc):
- warning = (line, errname)
+ def lint_error(path, line, col, msg_type, errname, errdesc):
+ warning = (line, msg_type, errname)
# Bad hack to fix line numbers on ambiguous else statements
# TODO: Fix tests.
if errname == 'ambiguous_else_stmt' and not warning in expected_warnings:
- warning = (line-1, errname)
+ warning = (line-1, msg_type, errname)
if warning in expected_warnings:
expected_warnings.remove(warning)
@@ -69,11 +69,11 @@
errors = []
if expected_warnings:
errors.append('Expected warnings:')
- for line, warning in expected_warnings:
+ for line, msg_type, warning in expected_warnings:
errors.append('\tline %i: %s' % (line+1, warning))
if unexpected_warnings:
errors.append('Unexpected warnings:')
- for line, warning, errdesc in unexpected_warnings:
+ for line, msg_type, warning, errdesc in unexpected_warnings:
errors.append('\tline %i: %s/%s' % (line+1, warning, errdesc))
if errors:
raise TestError('\n'.join(errors))
Modified: trunk/tests/conf/jscript_function_extensions-3.js
===================================================================
--- trunk/tests/conf/jscript_function_extensions-3.js 2016-12-29 22:10:19 UTC (rev 370)
+++ trunk/tests/conf/jscript_function_extensions-3.js 2016-12-30 22:48:30 UTC (rev 371)
@@ -23,5 +23,5 @@
this.val = null;
}
-function conf.jscript_function_extensions..ok(val) { /*warning:syntax_error*/
+function conf.jscript_function_extensions..ok(val) { /*error:syntax_error*/
}
Modified: trunk/tests/conf/jscript_function_extensions-4.js
===================================================================
--- trunk/tests/conf/jscript_function_extensions-4.js 2016-12-29 22:10:19 UTC (rev 370)
+++ trunk/tests/conf/jscript_function_extensions-4.js 2016-12-30 22:48:30 UTC (rev 371)
@@ -1,4 +1,4 @@
/*conf:+jscript_function_extensions*/
-function conf.jscript_function_extensions:onunload(val) { /*warning:syntax_error*/
+function conf.jscript_function_extensions:onunload(val) { /*error:syntax_error*/
}
Modified: trunk/tests/control_comments/conf-version-2.js
===================================================================
--- trunk/tests/control_comments/conf-version-2.js 2016-12-29 22:10:19 UTC (rev 370)
+++ trunk/tests/control_comments/conf-version-2.js 2016-12-30 22:48:30 UTC (rev 371)
@@ -3,5 +3,5 @@
/* Make sure that the control comment overrides the config file. */
function default_version() {
- yield true; /*warning:semi_before_stmnt*/
+ yield true; /*error:semi_before_stmnt*/
}
Modified: trunk/tests/control_comments/conf-version.js
===================================================================
--- trunk/tests/control_comments/conf-version.js 2016-12-29 22:10:19 UTC (rev 370)
+++ trunk/tests/control_comments/conf-version.js 2016-12-30 22:48:30 UTC (rev 371)
@@ -1,5 +1,5 @@
/*conf:+default-version text/javascript;version=1.7*/
function default_version() {
// TODO: Support js1.7
- yield true; /*warning:semi_before_stmnt*/
+ yield true; /*error:semi_before_stmnt*/
}
Modified: trunk/tests/errors/expected_tok.js
===================================================================
--- trunk/tests/errors/expected_tok.js 2016-12-29 22:10:19 UTC (rev 370)
+++ trunk/tests/errors/expected_tok.js 2016-12-30 22:48:30 UTC (rev 371)
@@ -1,4 +1,4 @@
function expected_tok() {
- return { a, }; /*warning:expected_tok*/
+ return { a, }; /*error:expected_tok*/
}
Modified: trunk/tests/errors/syntax_error.js
===================================================================
--- trunk/tests/errors/syntax_error.js 2016-12-29 22:10:19 UTC (rev 370)
+++ trunk/tests/errors/syntax_error.js 2016-12-30 22:48:30 UTC (rev 371)
@@ -1,4 +1,4 @@
function syntax_error() {
- &; /*warning:syntax_error*/
+ &; /*error:syntax_error*/
}
Modified: trunk/tests/html/e4x.html
===================================================================
--- trunk/tests/html/e4x.html 2016-12-29 22:10:19 UTC (rev 370)
+++ trunk/tests/html/e4x.html 2016-12-30 22:48:30 UTC (rev 371)
@@ -7,19 +7,19 @@
<script type="text/javascript">
// e4x is disabled by default, so HTML comments are single-line only.
var comment_a = <!--
- ? /*warning:syntax_error*/
+ ? /*error:syntax_error*/
-->;
</script>
<script type="text/javascript;e4x=1">/*warning:e4x_deprecated*/
// Explicitly enable e4x.
var comment_c = <!--
- ? /*warning:syntax_error*/
+ ? /*error:syntax_error*/
-->;
</script>
<script type="text/javascript;version=1.6;e4x=0">
// e4x is always enabled in 1.6+
var comment_b = <!--
- ? /*warning:syntax_error*/
+ ? /*error:syntax_error*/
-->;
</script>
</head>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2016-12-30 22:51:49
|
Revision: 372
http://sourceforge.net/p/javascriptlint/code/372
Author: matthiasmiller
Date: 2016-12-30 22:51:46 +0000 (Fri, 30 Dec 2016)
Log Message:
-----------
Stop hiding the fact that ambiguous_else_stmt is on the statement line, not on the "else".
Modified Paths:
--------------
trunk/test.py
trunk/tests/warnings/ambiguous_else_stmt.js
Modified: trunk/test.py
===================================================================
--- trunk/test.py 2016-12-30 22:48:30 UTC (rev 371)
+++ trunk/test.py 2016-12-30 22:51:46 UTC (rev 372)
@@ -53,12 +53,6 @@
def lint_error(path, line, col, msg_type, errname, errdesc):
warning = (line, msg_type, errname)
-
- # Bad hack to fix line numbers on ambiguous else statements
- # TODO: Fix tests.
- if errname == 'ambiguous_else_stmt' and not warning in expected_warnings:
- warning = (line-1, msg_type, errname)
-
if warning in expected_warnings:
expected_warnings.remove(warning)
else:
Modified: trunk/tests/warnings/ambiguous_else_stmt.js
===================================================================
--- trunk/tests/warnings/ambiguous_else_stmt.js 2016-12-30 22:48:30 UTC (rev 371)
+++ trunk/tests/warnings/ambiguous_else_stmt.js 2016-12-30 22:51:46 UTC (rev 372)
@@ -16,6 +16,6 @@
while (j) /*warning:ambiguous_nested_stmt*/
if (y) /*warning:ambiguous_nested_stmt*/
y--;
- else /*warning:ambiguous_else_stmt*/
- y++;
+ else
+ y++; /*warning:ambiguous_else_stmt*/
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2018-01-02 21:20:18
|
Revision: 374
http://sourceforge.net/p/javascriptlint/code/374
Author: matthiasmiller
Date: 2018-01-02 21:20:15 +0000 (Tue, 02 Jan 2018)
Log Message:
-----------
Improve error messages with invalid imports.
Modified Paths:
--------------
trunk/javascriptlint/lint.py
Added Paths:
-----------
trunk/tests/path_resolution/missing_import.html
trunk/tests/path_resolution/missing_import.js
Modified: trunk/javascriptlint/lint.py
===================================================================
--- trunk/javascriptlint/lint.py 2018-01-02 20:28:00 UTC (rev 373)
+++ trunk/javascriptlint/lint.py 2018-01-02 21:20:15 UTC (rev 374)
@@ -251,6 +251,7 @@
yield {
'type': 'external',
'jsversion': jsversion,
+ 'offset': tag['offset'],
'src': src,
}
elif tag['type'] == 'end':
@@ -278,13 +279,19 @@
def lint_files(paths, lint_error, encoding, conf=conf.Conf(), printpaths=True):
def lint_file(path, kind, jsversion, encoding):
- def import_script(import_path, jsversion):
+ def import_script(offset, import_path, jsversion):
# The user can specify paths using backslashes (such as when
# linting Windows scripts on a posix environment.
import_path = import_path.replace('\\', os.sep)
import_path = os.path.join(os.path.dirname(path), import_path)
- return lint_file(import_path, 'js', jsversion, encoding)
+ if os.path.isfile(import_path):
+ return lint_file(import_path, 'js', jsversion, encoding)
+ _report(offset, 'error', 'io_error', {
+ 'error': 'The file could not be found: %s' % import_path
+ })
+ return _Script()
+
def report_lint(node, errname, offset=0, **errargs):
assert errname in lintwarnings.warnings, errname
if conf[errname]:
@@ -326,7 +333,7 @@
continue
if script['type'] == 'external':
- other = import_script(script['src'], script['jsversion'])
+ other = import_script(script['offset'], script['src'], script['jsversion'])
lint_cache[normpath].importscript(other)
elif script['type'] == 'inline':
script_parts.append((script['offset'], script['jsversion'],
@@ -460,7 +467,7 @@
if not parms:
report(node, 'jsl_cc_not_understood')
else:
- import_paths.append(parms)
+ import_paths.append((node.start_offset, parms))
elif keyword == 'fallthru':
fallthrus.append(node)
elif keyword == 'pass':
@@ -503,8 +510,8 @@
report(fallthru, 'invalid_pass')
# Process imports by copying global declarations into the universal scope.
- for path in import_paths:
- script_cache.importscript(import_callback(path, jsversion))
+ for offset, path in import_paths:
+ script_cache.importscript(import_callback(offset, path, jsversion))
for name, node in declares:
declare_scope = script_cache.scope.find_scope(node)
Added: trunk/tests/path_resolution/missing_import.html
===================================================================
--- trunk/tests/path_resolution/missing_import.html (rev 0)
+++ trunk/tests/path_resolution/missing_import.html 2018-01-02 21:20:15 UTC (rev 374)
@@ -0,0 +1,10 @@
+<html>
+<head>
+ <script src="file_does_not_exist.js"></script> <!--/*error:io_error*/-->
+</head>
+<body>
+ <script>
+ /*jsl:import file_does_not_exist.js*/ /*error:io_error*/
+ </script>
+</body>
+</html>
Added: trunk/tests/path_resolution/missing_import.js
===================================================================
--- trunk/tests/path_resolution/missing_import.js (rev 0)
+++ trunk/tests/path_resolution/missing_import.js 2018-01-02 21:20:15 UTC (rev 374)
@@ -0,0 +1 @@
+/*jsl:import file_does_not_exist.js*/ /*error:io_error*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2018-01-02 21:26:52
|
Revision: 375
http://sourceforge.net/p/javascriptlint/code/375
Author: matthiasmiller
Date: 2018-01-02 21:26:49 +0000 (Tue, 02 Jan 2018)
Log Message:
-----------
Add a configuration setting for additional include directories.
Modified Paths:
--------------
trunk/javascriptlint/conf.py
trunk/javascriptlint/lint.py
trunk/test.py
Added Paths:
-----------
trunk/tests/path_resolution/include_dir.js
trunk/tests/path_resolution/include_dir_a/
trunk/tests/path_resolution/include_dir_a/import_helper.js
trunk/tests/path_resolution/include_dir_b/
trunk/tests/path_resolution/include_dir_b/import_helper.js
trunk/tests/path_resolution/include_dir_b/import_helper_b.js
Modified: trunk/javascriptlint/conf.py
===================================================================
--- trunk/javascriptlint/conf.py 2018-01-02 21:20:15 UTC (rev 374)
+++ trunk/javascriptlint/conf.py 2018-01-02 21:26:49 UTC (rev 375)
@@ -188,6 +188,18 @@
self._conf.loadfile(parm)
self.value = parm
+class IncludeDirSetting(Setting):
+ wants_parm = True
+ wants_dir = True
+ def __init__(self):
+ self.value = []
+ def load(self, enabled, parm, dir):
+ if not dir:
+ raise ConfError('The %s setting is only valid in a configuration file.' % parm)
+
+ abs_dir = os.path.abspath(os.path.join(dir, parm))
+ self.value.append(abs_dir)
+
class Conf:
def __init__(self):
recurse = BooleanSetting(False)
@@ -203,6 +215,7 @@
'process': ProcessSetting(recurse),
'default-version': JSVersionSetting(),
'conf': ConfSetting(self),
+ 'include-dir': IncludeDirSetting(),
# SpiderMonkey warnings
'no_return_value': BooleanSetting(True),
'equal_as_assign': BooleanSetting(True),
Modified: trunk/javascriptlint/lint.py
===================================================================
--- trunk/javascriptlint/lint.py 2018-01-02 21:20:15 UTC (rev 374)
+++ trunk/javascriptlint/lint.py 2018-01-02 21:26:49 UTC (rev 375)
@@ -283,12 +283,14 @@
# The user can specify paths using backslashes (such as when
# linting Windows scripts on a posix environment.
import_path = import_path.replace('\\', os.sep)
- import_path = os.path.join(os.path.dirname(path), import_path)
- if os.path.isfile(import_path):
- return lint_file(import_path, 'js', jsversion, encoding)
+ include_dirs = [os.path.dirname(path)] + conf['include-dir']
+ for include_dir in include_dirs:
+ abs_path = os.path.join(include_dir, import_path)
+ if os.path.isfile(abs_path):
+ return lint_file(abs_path, 'js', jsversion, encoding)
_report(offset, 'error', 'io_error', {
- 'error': 'The file could not be found: %s' % import_path
+ 'error': 'The file could not be found in any include paths: %s' % import_path
})
return _Script()
Modified: trunk/test.py
===================================================================
--- trunk/test.py 2018-01-02 21:20:15 UTC (rev 374)
+++ trunk/test.py 2018-01-02 21:26:49 UTC (rev 375)
@@ -21,12 +21,12 @@
class TestError(Exception):
pass
-def _get_conf(script):
+def _get_conf(script, script_dir):
regexp = re.compile(r"/\*conf:([^*]*)\*/")
text = '\n'.join(regexp.findall(script))
conf = javascriptlint.conf.Conf()
- conf.loadtext(_DEFAULT_CONF)
- conf.loadtext(text)
+ conf.loadtext(_DEFAULT_CONF, script_dir)
+ conf.loadtext(text, script_dir)
return conf
def _get_expected_warnings(script):
@@ -45,11 +45,14 @@
return warnings
def _testfile(path):
+ script_dir = os.path.dirname(path)
+ assert os.path.isabs(script_dir)
+
# Parse the script and find the expected warnings.
script = open(path).read()
expected_warnings = _get_expected_warnings(script)
unexpected_warnings = []
- conf = _get_conf(script)
+ conf = _get_conf(script, script_dir)
def lint_error(path, line, col, msg_type, errname, errdesc):
warning = (line, msg_type, errname)
Added: trunk/tests/path_resolution/include_dir.js
===================================================================
--- trunk/tests/path_resolution/include_dir.js (rev 0)
+++ trunk/tests/path_resolution/include_dir.js 2018-01-02 21:26:49 UTC (rev 375)
@@ -0,0 +1,5 @@
+/*conf:+include-dir include_dir_a*/
+
+/*jsl:import import_helper.js*/
+/*jsl:import import_helper_b.js*/ /*error:io_error*/
+import_helper();
Added: trunk/tests/path_resolution/include_dir_a/import_helper.js
===================================================================
--- trunk/tests/path_resolution/include_dir_a/import_helper.js (rev 0)
+++ trunk/tests/path_resolution/include_dir_a/import_helper.js 2018-01-02 21:26:49 UTC (rev 375)
@@ -0,0 +1,2 @@
+function import_helper() {
+}
Added: trunk/tests/path_resolution/include_dir_b/import_helper.js
===================================================================
Added: trunk/tests/path_resolution/include_dir_b/import_helper_b.js
===================================================================
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2018-01-02 21:55:27
|
Revision: 378
http://sourceforge.net/p/javascriptlint/code/378
Author: matthiasmiller
Date: 2018-01-02 21:55:24 +0000 (Tue, 02 Jan 2018)
Log Message:
-----------
Hide irrelevant command line options.
Modified Paths:
--------------
trunk/javascriptlint/jsl.py
trunk/setup.py
Modified: trunk/javascriptlint/jsl.py
===================================================================
--- trunk/javascriptlint/jsl.py 2018-01-02 21:42:44 UTC (rev 377)
+++ trunk/javascriptlint/jsl.py 2018-01-02 21:55:24 UTC (rev 378)
@@ -1,11 +1,17 @@
#!/usr/bin/python
# vim: ts=4 sw=4 expandtab
+try:
+ import hotshot
+ import hotshot.stats
+except ImportError:
+ hotshot = None
import fnmatch
import functools
+import optparse
import os
import sys
+import tempfile
import unittest
-from optparse import OptionParser
import conf
import fs
@@ -56,9 +62,6 @@
print "Developed by Matthias Miller (http://www.JavaScriptLint.com)"
def _profile_enabled(func, *args, **kwargs):
- import tempfile
- import hotshot
- import hotshot.stats
handle, filename = tempfile.mkstemp()
profile = hotshot.Profile(filename)
profile.runcall(func, *args, **kwargs)
@@ -70,12 +73,13 @@
func(*args, **kwargs)
def _main():
- parser = OptionParser(usage="%prog [options] [files]")
+ parser = optparse.OptionParser(usage="%prog [options] [files]")
add = parser.add_option
add("--conf", dest="conf", metavar="CONF",
help="set the conf file")
- add("--profile", dest="profile", action="store_true", default=False,
- help="turn on hotshot profiling")
+ if hotshot is not None:
+ add("--profile", dest="profile", action="store_true", default=False,
+ help="turn on hotshot profiling")
add("--recurse", dest="recurse", action="store_true", default=False,
help="recursively search directories on the command line")
if os.name == 'nt':
@@ -85,9 +89,9 @@
add("--enable-wildcards", dest="wildcards", action="store_true",
default=False, help="resolve wildcards in the command line")
add("--dump", dest="dump", action="store_true", default=False,
- help="dump this script")
+ help="dump this script" if not hasattr(sys, 'frozen') else optparse.SUPPRESS_HELP)
add("--unittest", dest="unittest", action="store_true", default=False,
- help="run the python unittests")
+ help="run the python unittests" if not hasattr(sys, 'frozen') else optparse.SUPPRESS_HELP)
add("--quiet", dest="verbosity", action="store_const", const=0,
help="minimal output")
add("--verbose", dest="verbosity", action="store_const", const=2,
Modified: trunk/setup.py
===================================================================
--- trunk/setup.py 2018-01-02 21:42:44 UTC (rev 377)
+++ trunk/setup.py 2018-01-02 21:55:24 UTC (rev 378)
@@ -53,7 +53,8 @@
'_ssl',
'_hashlib',
'socket',
- 'select'
+ 'select',
+ 'hotshot',
],
'bundle_files': 1,
'optimize': 1, # requires 1 to preserve docstrings
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2018-06-10 05:46:18
|
Revision: 380
http://sourceforge.net/p/javascriptlint/code/380
Author: matthiasmiller
Date: 2018-06-10 05:46:15 +0000 (Sun, 10 Jun 2018)
Log Message:
-----------
Add a warning against invalid ! usage
Modified Paths:
--------------
trunk/javascriptlint/lintwarnings.py
trunk/tests/warnings/for_in_missing_identifier.js
Modified: trunk/javascriptlint/lintwarnings.py
===================================================================
--- trunk/javascriptlint/lintwarnings.py 2018-01-02 22:12:15 UTC (rev 379)
+++ trunk/javascriptlint/lintwarnings.py 2018-06-10 05:46:15 UTC (rev 380)
@@ -107,6 +107,7 @@
'e4x_deprecated': 'e4x is deprecated',
'ambiguous_numeric_prop': 'numeric property should be normalized; use {normalized}',
'duplicate_property': 'duplicate property in object initializer',
+ 'ambiguous_not': 'the ! operator is ambiguous; use clarifying parentheses'
}
errors = {
@@ -686,6 +687,16 @@
return # Allow as constructors
raise LintWarning(node)
+@lookfor((tok.UNARYOP, op.NOT))
+def ambiguous_not(node):
+ # Avoid for(!s in o)
+ if node.parent and node.parent.kind == tok.IN:
+ raise LintWarning(node)
+
+ # Avoid use in comparisons.
+ if node.parent and node.parent.kind in (tok.EQOP, tok.RELOP):
+ raise LintWarning(node)
+
def _get_function_property_name(node):
# Ignore function statements.
if node.opcode in (None, op.CLOSURE):
Modified: trunk/tests/warnings/for_in_missing_identifier.js
===================================================================
--- trunk/tests/warnings/for_in_missing_identifier.js 2018-01-02 22:12:15 UTC (rev 379)
+++ trunk/tests/warnings/for_in_missing_identifier.js 2018-06-10 05:46:15 UTC (rev 380)
@@ -7,6 +7,6 @@
for (var prop2 in o)
o[prop2]++;
- for (!prop in o) /*warning:for_in_missing_identifier*/
+ for (!prop in o) /*warning:for_in_missing_identifier*/ /*warning:ambiguous_not*/
o[prop]++;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2018-06-10 05:55:24
|
Revision: 381
http://sourceforge.net/p/javascriptlint/code/381
Author: matthiasmiller
Date: 2018-06-10 05:55:22 +0000 (Sun, 10 Jun 2018)
Log Message:
-----------
Rename warning for clarity; add test.
Modified Paths:
--------------
trunk/javascriptlint/lintwarnings.py
trunk/tests/warnings/for_in_missing_identifier.js
Added Paths:
-----------
trunk/tests/warnings/unexpected_not.js
Modified: trunk/javascriptlint/lintwarnings.py
===================================================================
--- trunk/javascriptlint/lintwarnings.py 2018-06-10 05:46:15 UTC (rev 380)
+++ trunk/javascriptlint/lintwarnings.py 2018-06-10 05:55:22 UTC (rev 381)
@@ -107,7 +107,7 @@
'e4x_deprecated': 'e4x is deprecated',
'ambiguous_numeric_prop': 'numeric property should be normalized; use {normalized}',
'duplicate_property': 'duplicate property in object initializer',
- 'ambiguous_not': 'the ! operator is ambiguous; use clarifying parentheses'
+ 'unexpected_not': 'the ! operator is unexpected; use clarifying parentheses'
}
errors = {
@@ -688,7 +688,7 @@
raise LintWarning(node)
@lookfor((tok.UNARYOP, op.NOT))
-def ambiguous_not(node):
+def unexpected_not(node):
# Avoid for(!s in o)
if node.parent and node.parent.kind == tok.IN:
raise LintWarning(node)
Modified: trunk/tests/warnings/for_in_missing_identifier.js
===================================================================
--- trunk/tests/warnings/for_in_missing_identifier.js 2018-06-10 05:46:15 UTC (rev 380)
+++ trunk/tests/warnings/for_in_missing_identifier.js 2018-06-10 05:55:22 UTC (rev 381)
@@ -7,6 +7,6 @@
for (var prop2 in o)
o[prop2]++;
- for (!prop in o) /*warning:for_in_missing_identifier*/ /*warning:ambiguous_not*/
+ for (!prop in o) /*warning:for_in_missing_identifier*/ /*warning:unexpected_not*/
o[prop]++;
}
Added: trunk/tests/warnings/unexpected_not.js
===================================================================
--- trunk/tests/warnings/unexpected_not.js (rev 0)
+++ trunk/tests/warnings/unexpected_not.js 2018-06-10 05:55:22 UTC (rev 381)
@@ -0,0 +1,26 @@
+function unexpected_not() {
+ var i, j;
+ var f, s, o;
+
+ if (!i == -1) { /*warning:unexpected_not*/
+ return false;
+ }
+
+ if (!f() < -1) { /*warning:unexpected_not*/
+ return false;
+ }
+
+ if (!i != -1) { /*warning:unexpected_not*/
+ return false;
+ }
+
+ if (i != -1 || !j == -1) { /*warning:unexpected_not*/
+ return false;
+ }
+
+ if (!s in o) { /*warning:unexpected_not*/
+ return false;
+ }
+
+ return true;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2018-06-10 20:14:05
|
Revision: 382
http://sourceforge.net/p/javascriptlint/code/382
Author: matthiasmiller
Date: 2018-06-10 20:14:03 +0000 (Sun, 10 Jun 2018)
Log Message:
-----------
Split into two separate warnings.
Modified Paths:
--------------
trunk/javascriptlint/lintwarnings.py
trunk/tests/warnings/for_in_missing_identifier.js
Added Paths:
-----------
trunk/tests/warnings/unexpected_not_comparison.js
Removed Paths:
-------------
trunk/tests/warnings/unexpected_not.js
Modified: trunk/javascriptlint/lintwarnings.py
===================================================================
--- trunk/javascriptlint/lintwarnings.py 2018-06-10 05:55:22 UTC (rev 381)
+++ trunk/javascriptlint/lintwarnings.py 2018-06-10 20:14:03 UTC (rev 382)
@@ -107,7 +107,8 @@
'e4x_deprecated': 'e4x is deprecated',
'ambiguous_numeric_prop': 'numeric property should be normalized; use {normalized}',
'duplicate_property': 'duplicate property in object initializer',
- 'unexpected_not': 'the ! operator is unexpected; use clarifying parentheses'
+ 'unexpected_not_for_in': 'the ! operator is unexpected; add clarifying parentheses',
+ 'unexpected_not_comparison': 'the ! operator is unexpected; add clarifying parentheses or compare against !!',
}
errors = {
@@ -688,15 +689,34 @@
raise LintWarning(node)
@lookfor((tok.UNARYOP, op.NOT))
-def unexpected_not(node):
+def unexpected_not_for_in(node):
# Avoid for(!s in o)
if node.parent and node.parent.kind == tok.IN:
raise LintWarning(node)
+@lookfor((tok.UNARYOP, op.NOT))
+def unexpected_not_comparison(node):
# Avoid use in comparisons.
- if node.parent and node.parent.kind in (tok.EQOP, tok.RELOP):
+ if node.parent and node.parent.kind == tok.RELOP:
raise LintWarning(node)
+ if node.parent and node.parent.kind == tok.EQOP:
+ # Allow !!
+ kid, = node.kids
+ if kid.kind == tok.UNARYOP and kid.opcode == op.NOT:
+ return
+
+ # Allow when compared against !
+ for i, kid in enumerate(node.parent.kids):
+ if i == node.node_index:
+ continue
+ if kid.kind != tok.UNARYOP or kid.opcode != op.NOT:
+ break
+ else:
+ return
+
+ raise LintWarning(node)
+
def _get_function_property_name(node):
# Ignore function statements.
if node.opcode in (None, op.CLOSURE):
Modified: trunk/tests/warnings/for_in_missing_identifier.js
===================================================================
--- trunk/tests/warnings/for_in_missing_identifier.js 2018-06-10 05:55:22 UTC (rev 381)
+++ trunk/tests/warnings/for_in_missing_identifier.js 2018-06-10 20:14:03 UTC (rev 382)
@@ -7,6 +7,6 @@
for (var prop2 in o)
o[prop2]++;
- for (!prop in o) /*warning:for_in_missing_identifier*/ /*warning:unexpected_not*/
+ for (!prop in o) /*warning:for_in_missing_identifier*/ /*warning:unexpected_not_for_in*/
o[prop]++;
}
Deleted: trunk/tests/warnings/unexpected_not.js
===================================================================
--- trunk/tests/warnings/unexpected_not.js 2018-06-10 05:55:22 UTC (rev 381)
+++ trunk/tests/warnings/unexpected_not.js 2018-06-10 20:14:03 UTC (rev 382)
@@ -1,26 +0,0 @@
-function unexpected_not() {
- var i, j;
- var f, s, o;
-
- if (!i == -1) { /*warning:unexpected_not*/
- return false;
- }
-
- if (!f() < -1) { /*warning:unexpected_not*/
- return false;
- }
-
- if (!i != -1) { /*warning:unexpected_not*/
- return false;
- }
-
- if (i != -1 || !j == -1) { /*warning:unexpected_not*/
- return false;
- }
-
- if (!s in o) { /*warning:unexpected_not*/
- return false;
- }
-
- return true;
-}
Copied: trunk/tests/warnings/unexpected_not_comparison.js (from rev 381, trunk/tests/warnings/unexpected_not.js)
===================================================================
--- trunk/tests/warnings/unexpected_not_comparison.js (rev 0)
+++ trunk/tests/warnings/unexpected_not_comparison.js 2018-06-10 20:14:03 UTC (rev 382)
@@ -0,0 +1,51 @@
+function unexpected_not_comparison() {
+ var i, j;
+ var b, f, s, o;
+
+ if (!i == -1) { /*warning:unexpected_not_comparison*/
+ return false;
+ }
+
+ if (!f() < -1) { /*warning:unexpected_not_comparison*/
+ return false;
+ }
+
+ if (!i != -1) { /*warning:unexpected_not_comparison*/
+ return false;
+ }
+
+ if (i != -1 || !j == -1) { /*warning:unexpected_not_comparison*/
+ return false;
+ }
+
+ if (!s in o) { /*warning:unexpected_not_for_in*/
+ return false;
+ }
+
+ // Allow ! and !!
+ if (!!i == b) {
+ return false;
+ }
+ if (b == !!i) {
+ return false;
+ }
+ if (b === !i) { /*warning:unexpected_not_comparison*/
+ return false;
+ }
+ if (!i === b) { /*warning:unexpected_not_comparison*/
+ return false;
+ }
+ if (!!b === !i) {
+ return false;
+ }
+ if (!i === !!b) {
+ return false;
+ }
+
+ // Do not allow !! for relative comparison
+ if (!!i <= b) { /*warning:unexpected_not_comparison*/
+ return false;
+ }
+
+ return true;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2018-06-10 20:27:00
|
Revision: 384
http://sourceforge.net/p/javascriptlint/code/384
Author: matthiasmiller
Date: 2018-06-10 20:26:59 +0000 (Sun, 10 Jun 2018)
Log Message:
-----------
Fix the useless assignment warning.
Modified Paths:
--------------
trunk/javascriptlint/lintwarnings.py
trunk/tests/warnings/useless_assign.js
Modified: trunk/javascriptlint/lintwarnings.py
===================================================================
--- trunk/javascriptlint/lintwarnings.py 2018-06-10 20:17:00 UTC (rev 383)
+++ trunk/javascriptlint/lintwarnings.py 2018-06-10 20:26:59 UTC (rev 384)
@@ -473,11 +473,14 @@
@lookfor((tok.NAME, op.SETNAME))
def useless_assign(node):
- if node.parent.kind == tok.ASSIGN:
+ if node.parent.kind == tok.ASSIGN and node.parent.opcode not in (op.MUL, op.ADD, op.LSH,
+ op.RSH, op.URSH):
assert node.node_index == 0
value = node.parent.kids[1]
elif node.parent.kind == tok.VAR:
value = node.kids[0]
+ else:
+ value = None
if value and value.kind == tok.NAME and node.atom == value.atom:
raise LintWarning(node)
Modified: trunk/tests/warnings/useless_assign.js
===================================================================
--- trunk/tests/warnings/useless_assign.js 2018-06-10 20:17:00 UTC (rev 383)
+++ trunk/tests/warnings/useless_assign.js 2018-06-10 20:26:59 UTC (rev 384)
@@ -17,4 +17,19 @@
for (; ; i = i) { /*warning:useless_assign*/
i++;
}
+
+ // These could conceivably be meaningful.
+ i *= i;
+ i += i;
+ i >>= i;
+ i <<= i;
+ i >>>= i;
+
+ // These make no sense.
+ i /= i; /*warning:useless_assign*/
+ i -= i; /*warning:useless_assign*/
+ i %= i; /*warning:useless_assign*/
+ i &= i; /*warning:useless_assign*/
+ i |= i; /*warning:useless_assign*/
+ i ^= i; /*warning:useless_assign*/
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2018-06-10 20:42:01
|
Revision: 385
http://sourceforge.net/p/javascriptlint/code/385
Author: matthiasmiller
Date: 2018-06-10 20:41:58 +0000 (Sun, 10 Jun 2018)
Log Message:
-----------
Respect escaping within regular expressions.
Modified Paths:
--------------
trunk/jsengine/parser/__init__.py
trunk/jsengine/tokenizer/__init__.py
trunk/tests/warnings/misplaced_regex.js
Modified: trunk/jsengine/parser/__init__.py
===================================================================
--- trunk/jsengine/parser/__init__.py 2018-06-10 20:26:59 UTC (rev 384)
+++ trunk/jsengine/parser/__init__.py 2018-06-10 20:41:58 UTC (rev 385)
@@ -853,6 +853,15 @@
self.assertEqual(error.offset, 5)
else:
self.assert_(False)
+ try:
+ # Do not allow after an escape sequence, either.
+ parsestring('re = /[\\\n');
+ except JSSyntaxError as error:
+ self.assertEqual(error.offset, 5)
+ else:
+ self.assert_(False)
+ def testRegExpBugReport(self):
+ parsestring('validity = /[^\[\]/]/g')
def testUnterminatedComment(self):
try:
parsestring('/*')
Modified: trunk/jsengine/tokenizer/__init__.py
===================================================================
--- trunk/jsengine/tokenizer/__init__.py 2018-06-10 20:26:59 UTC (rev 384)
+++ trunk/jsengine/tokenizer/__init__.py 2018-06-10 20:41:58 UTC (rev 385)
@@ -215,10 +215,16 @@
return Token(tok.ERROR)
elif c == _Char.ord('['):
while True:
+ # Handle escaped characters, but don't allow line breaks after the escape.
c = stream.readchr()
+ escaped = False
+ if c == _Char.ord('\\'):
+ c = stream.readchr()
+ escaped = True
+
if c == _Char.ord('\n'):
return Token(tok.ERROR)
- elif c == _Char.ord(']'):
+ elif c == _Char.ord(']') and not escaped:
break
elif c == _Char.ord('\n'):
return Token(tok.ERROR)
Modified: trunk/tests/warnings/misplaced_regex.js
===================================================================
--- trunk/tests/warnings/misplaced_regex.js 2018-06-10 20:26:59 UTC (rev 384)
+++ trunk/tests/warnings/misplaced_regex.js 2018-06-10 20:41:58 UTC (rev 385)
@@ -21,6 +21,9 @@
i += /\/\./; /*warning:misplaced_regex*/
i = -/.*/; /*warning:misplaced_regex*/
+ /* legal usage */
+ var validity = /[^\[\]/]/g;
+
/* legal usage: return */
return /\/\./;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mat...@us...> - 2018-06-13 13:54:52
|
Revision: 386
http://sourceforge.net/p/javascriptlint/code/386
Author: matthiasmiller
Date: 2018-06-13 13:54:50 +0000 (Wed, 13 Jun 2018)
Log Message:
-----------
Rename "unexpected_not_for_in" to "unexpected_not_in".
Modified Paths:
--------------
trunk/javascriptlint/lintwarnings.py
trunk/tests/warnings/for_in_missing_identifier.js
trunk/tests/warnings/unexpected_not_comparison.js
Added Paths:
-----------
trunk/tests/warnings/unexpected_not_in.js
Modified: trunk/javascriptlint/lintwarnings.py
===================================================================
--- trunk/javascriptlint/lintwarnings.py 2018-06-10 20:41:58 UTC (rev 385)
+++ trunk/javascriptlint/lintwarnings.py 2018-06-13 13:54:50 UTC (rev 386)
@@ -107,7 +107,7 @@
'e4x_deprecated': 'e4x is deprecated',
'ambiguous_numeric_prop': 'numeric property should be normalized; use {normalized}',
'duplicate_property': 'duplicate property in object initializer',
- 'unexpected_not_for_in': 'the ! operator is unexpected; add clarifying parentheses',
+ 'unexpected_not_in': 'the ! operator is unexpected; add clarifying parentheses',
'unexpected_not_comparison': 'the ! operator is unexpected; add clarifying parentheses or compare against !!',
}
@@ -692,7 +692,7 @@
raise LintWarning(node)
@lookfor((tok.UNARYOP, op.NOT))
-def unexpected_not_for_in(node):
+def unexpected_not_in(node):
# Avoid for(!s in o)
if node.parent and node.parent.kind == tok.IN:
raise LintWarning(node)
Modified: trunk/tests/warnings/for_in_missing_identifier.js
===================================================================
--- trunk/tests/warnings/for_in_missing_identifier.js 2018-06-10 20:41:58 UTC (rev 385)
+++ trunk/tests/warnings/for_in_missing_identifier.js 2018-06-13 13:54:50 UTC (rev 386)
@@ -7,6 +7,6 @@
for (var prop2 in o)
o[prop2]++;
- for (!prop in o) /*warning:for_in_missing_identifier*/ /*warning:unexpected_not_for_in*/
+ for (!prop in o) /*warning:for_in_missing_identifier*/ /*warning:unexpected_not_in*/
o[prop]++;
}
Modified: trunk/tests/warnings/unexpected_not_comparison.js
===================================================================
--- trunk/tests/warnings/unexpected_not_comparison.js 2018-06-10 20:41:58 UTC (rev 385)
+++ trunk/tests/warnings/unexpected_not_comparison.js 2018-06-13 13:54:50 UTC (rev 386)
@@ -18,10 +18,6 @@
return false;
}
- if (!s in o) { /*warning:unexpected_not_for_in*/
- return false;
- }
-
// Allow ! and !!
if (!!i == b) {
return false;
Added: trunk/tests/warnings/unexpected_not_in.js
===================================================================
--- trunk/tests/warnings/unexpected_not_in.js (rev 0)
+++ trunk/tests/warnings/unexpected_not_in.js 2018-06-13 13:54:50 UTC (rev 386)
@@ -0,0 +1,18 @@
+function unexpected_not_in() {
+ var s, o;
+
+ if (!s in o) { /*warning:unexpected_not_in*/
+ return false;
+ }
+
+ if (!(s in o)) {
+ return false;
+ }
+
+ // Strange, but...if you really want to...
+ if ((!s) in o) {
+ return false;
+ }
+
+ return true;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|