Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explanation of JSHint's Bad line breaking before '+' error

Can someone explain to me why JSHint complains about the following,

window.location.href = String1
    + '#'
    + Sting2
    + '='
    + String3;

With the error, Bad line breaking before '+' error

I understand that this error can be configured with the laxbreak option, which is described as

This option suppresses most of the warnings about possibly unsafe line breakings in your code. It doesn't suppress warnings about comma-first coding style. To suppress those you have to use laxcomma (see below).

This explanation is pretty terse and I am curious about why breaking lines this way is considered bad or lax in the first place.

Keep in mind I am not trying to start a holy war here, I am just looking for an objective answer about why the JSHint folks think this is bad, whether it is just a style preference they are injecting into their linter (I thought JSLint was the opinionated linter), or if there is something that can go wrong on certain interpreters when line breaking this way.

like image 390
James McMahon Avatar asked Oct 15 '22 09:10

James McMahon


1 Answers

It's a style guide to avoid statements that could be liable to assumptions about automatic semicolon insertion.

The idea is that you make it clear by the end of a line whether the expression ends there or could be continued on the next line.

like image 171
Barney Avatar answered Nov 13 '22 09:11

Barney