-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
lint/noUselessElse
incorrectly flags valid else
#924
Comments
Actually the intended suggestion is: function test() {
let value;
if (a) {
value = 1;
} else {
if (b) {
return 2;
}
value = 3;
}
return value;
} |
The CLI does not make it clear then.
Personally I'm 👎 on suggesting to ADD indentation/nested code, the |
I think you are right. When I implemented the rule I was wondering the same thing. I chose this behavior because this was the simplest one (we just have to check the previous branch, not all of them). Let's think a bit about that and change the rule to ignore this kind of code. |
noUselessElse
incorrectly flags valid else
noUselessElse
incorrectly flags valid else
Came here to report the same bug. If there is a branch before that doesn't return / break / continue then the rule can't be applied. |
noUselessElse
incorrectly flags valid else
lint/noUselessElse
incorrectly flags valid else
Environment information
What happened?
This an overly simplified example to trigger the bug:
https://biomejs.dev/playground/?indentStyle=space"eStyle=single&trailingComma=none&code=ZgB1AG4AYwB0AGkAbwBuACAAdABlAHMAdAAoACkAIAB7AAoAIAAgAGwAZQB0ACAAdgBhAGwAdQBlADsACgAKACAAIABpAGYAIAAoAGEAKQAgAHsACgAgACAAIAAgAHYAYQBsAHUAZQAgAD0AIAAxADsACgAgACAAfQAgAGUAbABzAGUAIABpAGYAIAAoAGIAKQAgAHsACgAgACAAIAAgAHIAZQB0AHUAcgBuACAAMgA7AAoAIAAgAH0AIABlAGwAcwBlACAAewAKACAAIAAgACAAdgBhAGwAdQBlACAAPQAgADMAOwAKACAAIAB9AAoACgAgACAAcgBlAHQAdQByAG4AIAB2AGEAbAB1AGUAOwAKAH0ACgA%3D
Expected result
If I follow biome's suggestions with the above code, I'll end up with
which breaks the previous logic.
If the
a
condition is truthy, then the lastelse
should not run, regardless of what theb
condition/block does.Code of Conduct
The text was updated successfully, but these errors were encountered: