I recently added a script to run JSLint over any javascript files that were changed in my last batch of commits when I push changes to our main repository (if you’re interested, you can take a look). Immediately, I had my feelings hurt when it started reporting a bunch of errors and warnings.
Most of them I agreed with, but the ambiguous end of line warning when the line was catching syntax that I had very purposefully used to increase readability (for me). Basically, this warning appears if a line doesn’t end with an operator like ‘+’ or ‘.’ that indicates there’s another part required. However, I like to use these operators at the beginning of a new line in order to make it easy to scan and see which lines are continuations.
For example, I would write my jQuery code like this:
$("#someId").after("<br />")
.css("color","red")
.show();
However, this will generate “lint warning: unexpected end of line; it is ambiguous whether these lines are part of the same statement” for the last two lines. Instead, JSLint expects the code to be written like this:
$("#someId").after("<br />").
css("color","red").
show();
To me, this makes it too easy to not notice that methods like ‘css’ and ‘show’ are properties of an object and not just individual methods. On the other hand, I wasn’t sure whether it would be a good idea to just ignore a warning from lint because it would look prettier.
Therefore, I talked it over with my coworker, Xavi, and he suggested we turn off the Lint check for this ‘error’. In addition to us, pretty much the whole jQuery community agrees with our formatting. As long as we pay attention to the other errors in Lint, we shouldn’t be writing code with missing semi-colons.
To fix this, I just added a configuration file with a single line: “-ambiguous_newline”. Once I referenced the config file in our script, these errors stopped being reported.


July 3, 2010 at 6:49 am
Hi, as a webdesigner I always use these statements on a single line. Another example is conditional statements (using
on multiple lines its a nono!…
So even if jquery dont mind to step out of javascript standards, I do not…