javascriptlint
javascriptlint copied to clipboard
array on LHS handled poorly
With this file:
#! /usr/bin/env node
function foo() {
return ['a', 'b']
}
[v1, v2] = foo();
console.log([v1, v2])
jsl fails miserably
$ PYTHONPATH=.:build ./javascriptlint/jsl fail
JavaScript Lint
Developed by Matthias Miller (http://www.JavaScriptLint.com)
/home/mgerdts/javascriptlint/fail
/home/mgerdts/javascriptlint/fail(4): warning: missing semicolon
Traceback (most recent call last):
File "./javascriptlint/jsl", line 14, in <module>
javascriptlint.main()
File "/home/mgerdts/javascriptlint/javascriptlint/jsl.py", line 142, in main
profile_func(_lint, paths, conf_, options.printlisting)
File "/home/mgerdts/javascriptlint/javascriptlint/jsl.py", line 66, in _profile_disabled
func(*args, **kwargs)
File "/home/mgerdts/javascriptlint/javascriptlint/jsl.py", line 32, in _lint
lint.lint_files(paths, lint_error, conf=conf_, printpaths=printpaths)
File "/home/mgerdts/javascriptlint/javascriptlint/lint.py", line 340, in lint_files
lint_file(path, 'js', None)
File "/home/mgerdts/javascriptlint/javascriptlint/lint.py", line 331, in lint_file
_lint_script_parts(script_parts, lint_cache[normpath], _lint_error, conf, import_script)
File "/home/mgerdts/javascriptlint/javascriptlint/lint.py", line 540, in _lint_script_parts
report_native, report_lint, import_callback)
File "/home/mgerdts/javascriptlint/javascriptlint/lint.py", line 495, in _lint_script_part
_lint_node(root, visitors)
File "/home/mgerdts/javascriptlint/javascriptlint/lint.py", line 639, in _lint_node
_lint_node(child, visitors)
File "/home/mgerdts/javascriptlint/javascriptlint/lint.py", line 639, in _lint_node
_lint_node(child, visitors)
File "/home/mgerdts/javascriptlint/javascriptlint/lint.py", line 639, in _lint_node
_lint_node(child, visitors)
File "/home/mgerdts/javascriptlint/javascriptlint/lint.py", line 639, in _lint_node
_lint_node(child, visitors)
File "/home/mgerdts/javascriptlint/javascriptlint/lint.py", line 635, in _lint_node
visitor(node)
File "/home/mgerdts/javascriptlint/javascriptlint/lint.py", line 569, in onpush
ret = visitor(node)
File "/home/mgerdts/javascriptlint/javascriptlint/warnings.py", line 417, in useless_assign
if value and value.kind == tok.NAME and node.atom == value.atom:
UnboundLocalError: local variable 'value' referenced before assignment
From the error message, it is clear that value is used before assignment. The correct fix is dependent on node version. In older versions of node, it seems arrays on the LHS are not allowed. node v9.3.0 is fine with it.
$ node --version
v0.12.3
$ ./fail
/home/mgerdts/javascriptlint/fail:7
[v1, v2] = foo();
^
ReferenceError: Invalid left-hand side in assignment
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
# node --version
v9.3.0
[root@buglets ~]# ./fail
[ 'a', 'b' ]