google / closure-linter

Automatically exported from code.google.com/p/closure-linter
Apache License 2.0
109 stars 37 forks source link

Bad missing semi-colon error when 'else' is not followed by an opening brace. #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Run fixjsstyle in a file containing this code snippet:
if(true)
     alert(true);
else
     alert(false);

What is the expected output? What do you see instead?
Instead of the expected behavior I saw...
if(true)
     alert(true);
else;
     alert(false);

What version of the product are you using? On what operating system?
2.2.1, I think at this time it's the latest.

Please provide any additional information below.
The problem is a ";" after the else statement.

Original issue reported on code.google.com by 241...@gmail.com on 2 Sep 2010 at 4:08

GoogleCodeExporter commented 9 years ago
gjslint is improperly reporting a missing semi-colon error after the else, such 
that fixjsstyle is now trying to fix this incorrect error.

We should fix this, but if you wanted you can work around the error by using 
braces in your else statement.

if (true) { 
  alert(true);
} else {
  alert(false);
}

Original comment by a...@google.com on 3 Sep 2010 at 3:00

GoogleCodeExporter commented 9 years ago

Original comment by a...@google.com on 3 Sep 2010 at 3:00

GoogleCodeExporter commented 9 years ago

Original comment by a...@google.com on 3 Sep 2010 at 7:13

GoogleCodeExporter commented 9 years ago
There is a related error regarding the var keyword:

$> cat with_var.js
var
  a = 2,
  b = 3;

console.log(a, b);

$> node with_var.js 
2 3

$> fixjsstyle with_var.js
Fixed 1 errors in with_var.js

$ cat with_var.js 
var;
  a = 2,
  b = 3;

console.log(a, b);

$> node with_var.js

with_var.js:1
var;
   ^
SyntaxError: Unexpected token ;
    at Module._compile (node.js:457:37)
    at Module._loadScriptSync (node.js:468:10)
    at Module.loadSync (node.js:338:12)
    at Object.runMain (node.js:521:24)
    at node.js:751:10

.. or should this be a separate issue ?

Original comment by filip.noetzel on 13 Sep 2010 at 9:14

GoogleCodeExporter commented 9 years ago
It would be better to track this as a separate issue. While they manifest in 
the same way (bad missing semi-colon error) their cause within the linter is 
different.

Original comment by a...@google.com on 14 Sep 2010 at 3:18

GoogleCodeExporter commented 9 years ago
I've filed issue 10 Bad missing semi-colon error when line ends with var 
keyword to track this as a separate issue.

The fix to this issue around the else keyword is already complete and will we 
part of the next GJsLint release soon. Hopefully we can fix the var issue in 
the release after that.

Original comment by a...@google.com on 16 Sep 2010 at 1:53

GoogleCodeExporter commented 9 years ago
This issue should be fixed in version 2.2.5. Issue 10, split off from this 
issue, is still open as of version 2.2.5.

Original comment by a...@google.com on 17 Sep 2010 at 1:46