closure-linter
closure-linter copied to clipboard
A missing closing brace can cause the linter to explode in --strict mode.
What steps will reproduce the problem?
1. Enter the following as lint_test.js:
-----------------------------------------------------
goog.provide('app.LintTest');
/**
* Small example for the problem with Google's JSLint
* @param {number} i An integer.
* @constructor
*/
app.LintTest = function(i) {
if (goog.isDef(i)) {
if (i < 5) {
alert('Less than 5');
}
else {
alert('Greater than or equal to 5.');
}
};
-----------------------------------------------------
2. Run the command 'gjslint lint_test.js'. You see an error which hints at the
mistake.
3. Run the command 'gjslint --strict lint_test.js'. You see the stack trace
listed below.
What is the expected output? What do you see instead?
I would expect to see an error message like you see without using the --strict
flag, or at the very least a controlled erroneous return. Instead, I see the
stack trace shown below.
[04:12:18 jyoung: /devel] $ gjslint --strict lint_test.js
Traceback (most recent call last):
File "/usr/local/bin/gjslint", line 8, in <module>
load_entry_point('closure-linter==2.2.1', 'console_scripts', 'gjslint')()
File "build/bdist.macosx-10.6-universal/egg/closure_linter/gjslint.py", line 100, in main
File "build/bdist.macosx-10.6-universal/egg/closure_linter/checker.py", line 80, in Run
File "build/bdist.macosx-10.6-universal/egg/closure_linter/checkerbase.py", line 155, in Check
File "build/bdist.macosx-10.6-universal/egg/closure_linter/checkerbase.py", line 228, in CheckLines
File "build/bdist.macosx-10.6-universal/egg/closure_linter/javascriptlintrules.py", line 82, in CheckToken
File "build/bdist.macosx-10.6-universal/egg/closure_linter/ecmalintrules.py", line 250, in CheckToken
File "build/bdist.macosx-10.6-universal/egg/closure_linter/indentation.py", line 206, in CheckToken
File "build/bdist.macosx-10.6-universal/egg/closure_linter/indentation.py", line 440, in _Add
AttributeError: 'NoneType' object has no attribute 'line_number'
What version of the product are you using? On what operating system?
I just checked out, built, and installed the tool from subversion today, so Rev
5 from svn. Part of the stack trace shows what looks like a version number:
load_entry_point('closure-linter==2.2.1'
Original issue reported on code.google.com by [email protected] on 19 Sep 2010 at 8:23
I observe this issue for missing quotes as well.
var foo = function() {
alert('in function foo.);
return 0;
};
I have tested this with closure-linter 2.2.5 and 2.2.6 using python 2.6 and
python 2.7.
Original comment by [email protected] on 15 Nov 2010 at 2:52
At the very least GJsLint should report an error that the file does not parse,
if not provide a more useful and specific error. It definitely shouldn't error
with an ugly stack trace.
Original comment by [email protected] on 15 Nov 2010 at 4:55
- Changed state: Accepted
Attached is a patch that raises the following behavior:
>>SNIP>>
$ cat baz.js
var foo = function() {
alert('in function foo.);
};
$ python closure_linter/gjslint.py --strict baz.js
----- FILE : baz.js -----
Line 2, E:0130: Multi-line strings are not allowed
Line 3, E:0301: File ended in mode "single_quote_string".
Line 3, E:-002: INTERNAL ERROR: indentation stack is not empty: [
<JavaScriptToken: 1, operator, "=", {}, MetaData(Context(var > statement > root), optype: 'binary')> OVERRIDDEN [by "{"] {is_block: False, is_transient: True},
<JavaScriptToken: 1, {, "{", {}, MetaData(Context(block > var > statement > root))> {is_block: True, is_transient: False},
<JavaScriptToken: 2, (, "(", {}, MetaData(Context(group > statement > block > var > statement > root))> {is_block: False, is_transient: False}]
Found 3 errors, including 0 new errors, in 1 files (0 files OK).
Some of the errors reported by GJsLint may be auto-fixable using the script
fixjsstyle. Please double check any changes it makes and report any bugs. The
script can be run by executing:
fixjsstyle --strict baz.js
<<SNAP<<
I don't think that's a beautiful way to end the program ("INTERNAL ERROR",
etc.) but its way better than blurping out a stacktrace.
Original comment by filip.noetzel on 20 Feb 2011 at 8:54
Attachments: