Prevent confusing if-statement usage
See original GitHub issueIs there a way to configure eslint to prevent confusing if-statements like the following?
if (condition) {
// stuff
} if (anotherUnrelatedCondition) {
// more
}
This is confusing because at first glance it looks like the second if
is an else if
, but it’s not.
I couldn’t find a rule to enforce this. It seems that this could potentially be part of the keyword-spacing
rule. Perhaps an option to require newlines, not just a space, before certain keywords.
But I’m not sure this is the right approach. Thoughts?
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (10 by maintainers)
Top Results From Across the Web
c# - Confusing If Statement? - Stack Overflow
Then the design is faulty. You should avoid inherently negative bools: use isOkay instead of isFaulty, hasMembers instead of hasNoMembers, ...
Read more >Developer insists if statements shouldn't have negated ...
Explicit else block. The first rule just pollutes the code and makes it neither more readable, nor less error-prone.
Read more >if / else errors - learn how to fix these - Codecademy
A typical if () statement looks like this. Depending on what you are checking for, the `else if` and `else` blocks may not...
Read more >Else Clauses on Loop Statements
If we call the else clause on an if statement a “conditional else”, ... The simplest approach for any new language to take...
Read more >4. More Control Flow Tools — Python 3.11.1 documentation
Besides the while statement just introduced, Python uses the usual flow ... Look closely: the else clause belongs to the for loop, not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Closing because this should now be solved by
padding-line-between-statements
.Maybe
no-stalking-if