You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the description for the noUselessElse rule reads
Disallow else block when the if block breaks early.
If an if block breaks early using a breaking statement (return, break, continue, or throw), then the else block becomes useless. Its contents can be placed outside of the block.
which is not very clear in explaining why the else block becomes useless. This could result in people who cannot interpret the reasoning of why the else block becomes useless to disable the rule.
Expected result
A better alternative could be something like this
If an if block breaks early using a breaking statement (return, break, continue, or throw), the else block becomes unnecessary. This is because the contents of the else block will never be executed in conjunction with the if block, as the breaking statement ensures the control flow exits the if block immediately. Therefore, the else block is redundant, and its contents can be more effectively placed outside of the block, enhancing clarity and efficiency in the code structure.
Let me know if I should modify anything or make a PR for it.
Code of Conduct
I agree to follow Biome's Code of Conduct
The text was updated successfully, but these errors were encountered:
Therefore, the else block is redundant, and its contents can be more effectively placed outside of the block, enhancing clarity and efficiency in the code structure.
if(a){return ...;}elseif(b){return ...;}
Here the else is redundant, but the condition is not, so the "block" should remain:
if(a){return ...;}if(b){return ...;}
I think rather than talking about "blocks", the description should talk about the else clause itself.
Environment information
What happened?
Currently, the description for the
noUselessElse
rule readswhich is not very clear in explaining why the
else
block becomes useless. This could result in people who cannot interpret the reasoning of why the else block becomes useless to disable the rule.Expected result
A better alternative could be something like this
Let me know if I should modify anything or make a PR for it.
Code of Conduct
The text was updated successfully, but these errors were encountered: