34

It's giving me the error "Bad line breaking before ','" because I have code like the following

var one = 1
  , two = 2
  , three = 3
  ;

If I put the , at the end of the line instead of the beginning of the next, it doesn't complain. But I want to code this way. Is there a way I can make it not show this warning?

I looked though JSHint's options but there isn't anything pertaining to this error.

2 Answers 2

33

As mentioned in the comments of the laxbreak answer, laxcomma option should actually be used for this particular situation (it has been implemented in the meantime). See http://jshint.com/docs/options/ for details.

0
14

laxbreak = true is the option to set.

You can find the option on the main page of JSHint site as "About unsafe line breaks".

5
  • Thank you, that did it! I didn't think this option was for that when I saw it because it says "unsafe line breaks". I don't see how the line breaks in my code above are unsafe. I assumed it was talking about line breaks after a return/break/continue.
    – fent
    Dec 18, 2011 at 2:26
  • @DeaDEnD: That option is not checking if the code will really result in a problem or have no special handling for var (AFAIK). It is checking line endings on each line - it covers return statements but also this.
    – kubetz
    Dec 18, 2011 at 3:05
  • 2
    (JSHint maintainer here) By the way, we are working on separating laxbreak option with this comma-first notation. Dec 19, 2011 at 17:49
  • @AntonKovalyov I noticed the upcoming laxcomma option, but I thought that laxcomma is only a subset of laxbreak so we can set laxbreak = true and laxcomma = false but not vice versa. So we cannot setup JSHint to have no problem with this var statement but report other unsafe line breaks. Am I wrong?
    – kubetz
    Dec 19, 2011 at 18:00
  • We still haven't made the decision about how laxcomma should work—it is tricky so if you have any thoughts or suggestions, I'd greatly appreciate them. Dec 20, 2011 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.