Rule proposal: no-dangling-else
- Disallow dangling else ambiuguity
#2515
Labels
no-dangling-else
- Disallow dangling else ambiuguity
#2515
Description
Detect Dangling else ambiguity, especially around if statements without brackets.
Fail
Pass
Proposed rule name
no-dangling-else
Additional Info
The allowed case should be "Disallowing the statement following a "then" to be an "if" itself (it may however be a pair of statement brackets containing only an if-then-clause)." - Taken from Avoiding_ambiguity_by_changing_the_syntax section in the Wikipedia article.
While there are other ways to prevent this problem like enforcing braces or enforcing formatting rules to make the problem obvious, nothing I found helps finding mistakes like these (which cause bugs in logic and needs to be fixed by a human) in an existing codebase.
e.g. Eslint's curly would use the latter accepted form when fixing, while that is how it's interpreted by JavaScript, there was an ambiguity when the code was written.
The text was updated successfully, but these errors were encountered: