Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No warning for semi-colon after if-condition #3074

Open
partridgetim opened this issue Dec 9, 2016 · 2 comments
Open

No warning for semi-colon after if-condition #3074

partridgetim opened this issue Dec 9, 2016 · 2 comments

Comments

@partridgetim
Copy link

if (false);
{
alert('this will execute. The semi-colon after the if-condition is likely a mistake but no warning is given');
}

@jugglinmike
Copy link
Member

Thanks for the report. If you enable JSHint's curly option, then you will receive warnings about the use of a "brace-less" if statements. That will catch the type of programming mistakes that your example describes. Does that work for you?

@partridgetim
Copy link
Author

Sure, that would catch this mistake, but sometimes I want to use a braceless if statement so I'll just work without enabling that option. It took me a few minutes to spot the semi-colon. I debugged and couldn't believe my eyes when the condition evaluated to false and my if-block still executed. I guess this is legal JavaScript: a braceless if-statement followed by a block statement. It just seemed to me like this was a perfect spot for jshint to give a warning like "Did you intend to write a braceless if-statement followed by an unlabelled block-statement or is the semi-colon after the if-condition a mistake?" Maybe it is such an edge case though that it's not worth implementing but I just thought I'd pass it along in case. It's my reflex of adding semi-colons at the end of lines that bit me. Thanks for the quick response and congrats on the great tool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants