How to Check for Semicolons After IF Statements in ESLint?

0
13
Asked By CuriousCoder84 On

I'm looking for a way to have ESLint detect when there's a semicolon following an if statement. For example, code like `if (mytest); { myFunction(); }` should raise a flag. I'd also like it to handle one-line blocks where the braces are optional, such as: `if (myTest); myFunction();`. If there's a rule that extends this to WHILE/ FOR statements, that'd be a bonus! I know I could use grep to catch this, but I prefer having ESLint do it to avoid such errors before commits.

5 Answers

Answered By HelpfulHannah93 On

Check out this GitHub issue that discusses your problem: https://github.com/eslint/eslint/issues/13785. You can use the rule `'nonblock-statement-body-position': ['error', 'below']` to make it clearer when there's a mistake, like this: `if (mytest) ; myFunction();`. It's a good start!

CuriousCoder84 -

Thanks for the tip! I saw in the issue some alternative solutions too that might work well for me.

Answered By SatiricalSandy On

New troll post format just dropped! Why not just ask some AI to whip up a custom linter for this mess?

Answered By ConfusedCoder17 On

What even is this JavaScript? Seems a bit questionable, right?

Answered By LogicLover88 On

You might think grep could handle this, but it really can't in every situation. Regular expressions can't cover it perfectly. It's why compilers rely on parsers after the regex step!

Answered By StraightTalker21 On

Seriously, just write JavaScript like a normal person! Nobody wants to deal with code that looks that messy.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.