Jshint: Request option to suppress semicolon

Created on 15 Sep 2011  ·  7Comments  ·  Source: jshint/jshint

Hi,

I just started using JSHint and it nicely found several problems. However, in my coding style, it seems that I place semicolons in places where it's not necessary in JavaScript (a holdover from programming in other languages where it is necessary, I suppose).

Would it be possible to add an option to suppress messages such as: "Line 190 }; Unnecessary semicolon."

Thanks.

Most helpful comment

I have found the option to ignore the warning:
add following to .jshintrc file. I use sublimelinter-jshint, it works.

"-W032": false

https://jslinterrors.com/unnecessary-semicolon
http://kuljit.co.uk/configuring-jshint-with-a-jshintrc-configuration-file/

All 7 comments

I'd like to see your code. Basically, if it a semicolon's unnecessary in JS, it's unnecessary in all the other C like languages. Probably. Feel free to prove me wrong.

JSHint is here to help you fix errors like that, not to ignore them.

a) "Other languages", not "other C like languages".

b) It's not an error. It runs fine in all browsers I test in. Even the sense of the message, "Unnecessary semicolon", rather than say "Invalid semicolon", says it's not an error. Isn't it the point of JSHint to make testing for non-errors selectable by the programmer? Isn't that why JSHint was forked off JSLint in the first place?

Is it then the case that a Lint-like program that forces you to add "{" and "}" when not needed is bad, but one that forces you to remove ";" when not needed is good? Whose choice should that be?

Yes, it's not an error. The browser simply parses it as an empty statement.

Yeah, you're right, we should just add an option to accept any code and say it works fine.

Seriously man, what are you using JSHint for if not to catch little mistakes that the browser won't?

Oh yeah, and purely out of curiosity, what languages are you used to? I can't think of a language with semicolons that isn't C-like.

The goal of JSHint is to catch all kind of mistakes for you, however, if a person believes that they know better—more power to them. I am working towards allowing people to turn off any warning in JSHint while providing a very safe (and strict) set of defaults.

@alpha123, I feel you but different people use the tool for different purposes. If somebody wants to use it _only_ for catching leaking globals—well, I don't have anything against that approach even if I don't embrace it myself.

@SidNM, Thanks for the ticket. I am closing it since I am already working on a solution that incorporates what has been asked here.

"I can't think of a language with semicolons that isn't C-like"
well here is one: Delphi (Pascal)

Did this ever get implemented? It's almost three years old and I'm still having the same problem. If the comprehensive solution isn't coming anytime soon, could the simple solution get implemented in the meantime? I want to disable unnecessary semicolon warnings globally but leave in the crucial missing semicolon warnings that could cause real problems.

I have found the option to ignore the warning:
add following to .jshintrc file. I use sublimelinter-jshint, it works.

"-W032": false

https://jslinterrors.com/unnecessary-semicolon
http://kuljit.co.uk/configuring-jshint-with-a-jshintrc-configuration-file/

Was this page helpful?
0 / 5 - 0 ratings