closure-linter icon indicating copy to clipboard operation
closure-linter copied to clipboard

incorrect "else" block warning

Open GoogleCodeExporter opened this issue 10 years ago • 0 comments

Sometimes I write code formatted like this:
----------
if (condA) {
    console.log('A');
} else // <- ?
if (condB) {
    console.log('B');
} else {
    console.log('else')
}
----------
(I do this when condA and condB are symmetrical and could be swapped without 
side-effects).

In this case linter complains "Missing semicolon at end of line" (line 3).
I.e it seems to believe I should add a semicolon directly at "else;".
This is clearly am incorrect warning.
(If I do add a ";" it luckily catches that and reports as an error).

---------

A second note is that linter doesn't seem to enforce any particular style for 
the last "else" though. I can write all combos of else and braces without 
complaint. 
----
} else {
 ..
}

---
} else
{
..
}
--- 
}
else
{
..
}
------

To me this kindof indicates I could be allowed to format middle "else" to my 
liking too? (I don't find anything about this if-else in the Google code style 
guide either. Although I'm aware that writing "else if" on same line is more 
common).

Regards
/ Fredrik Blomqvist

Original issue reported on code.google.com by [email protected] on 18 Oct 2013 at 8:38

GoogleCodeExporter avatar Jun 17 '15 06:06 GoogleCodeExporter