-
-
Notifications
You must be signed in to change notification settings - Fork 467
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
💅 noUselessElse does not respect else if conditional #4354
Comments
Your point is valid, but so is the rule, that is why it belongs to the style group. It enforces a certain coding style. The rule is doing exactly what it is meant to, so it's not a bug. I would argue that it shouldn't be recommended, but that's a breaking change. We might consider it for v2. Feel free to open a discussion |
The rule is intended to report this kind of code because your code is equivalent to: import utils from "./utils";
function writeFilesWhenPermitted(returnEarly: boolean): string {
if (returnEarly) {
return "File write skipped";
}
if (utils.userHasPermissions()) {
utils.writeFiles();
return "Files written successfully";
}
return "Not permitted to write files";
}
I really don't understand your point. |
@ematipico @Conaclos |
You can suppress the rule for that code branch: if (foo) {
return false;
} // biome-ignore lint/style/noUselessElse: better reading
else if () {
return false;
} |
For now there is no way of getting the behavior you want (except by using ignore comments). We could consider adding |
Environment information
Rule name
noUselessElse
Playground link
https://biomejs.dev/playground/?code=aQBtAHAAbwByAHQAIAB1AHQAaQBsAHMAIABmAHIAbwBtACAAIgAuAC8AdQB0AGkAbABzACIAOwAKAAoAZgB1AG4AYwB0AGkAbwBuACAAdwByAGkAdABlAEYAaQBsAGUAcwBXAGgAZQBuAFAAZQByAG0AaQB0AHQAZQBkACgAcgBlAHQAdQByAG4ARQBhAHIAbAB5ADoAIABiAG8AbwBsAGUAYQBuACkAOgAgAHMAdAByAGkAbgBnACAAewAKACAAIABpAGYAIAAoAHIAZQB0AHUAcgBuAEUAYQByAGwAeQApACAAewAKACAAIAAgACAAcgBlAHQAdQByAG4AIAAiAEYAaQBsAGUAIAB3AHIAaQB0AGUAIABzAGsAaQBwAHAAZQBkACIAOwAKACAAIAB9ACAAZQBsAHMAZQAgAGkAZgAgACgAdQB0AGkAbABzAC4AdQBzAGUAcgBIAGEAcwBQAGUAcgBtAGkAcwBzAGkAbwBuAHMAKAApACkAIAB7AAoAIAAgACAAIAB1AHQAaQBsAHMALgB3AHIAaQB0AGUARgBpAGwAZQBzACgAKQA7AAoAIAAgACAAIAByAGUAdAB1AHIAbgAgACIARgBpAGwAZQBzACAAdwByAGkAdAB0AGUAbgAgAHMAdQBjAGMAZQBzAHMAZgB1AGwAbAB5ACIAOwAKACAAIAB9AAoAIAAgAHIAZQB0AHUAcgBuACAAIgBOAG8AdAAgAHAAZQByAG0AaQB0AHQAZQBkACAAdABvACAAdwByAGkAdABlACAAZgBpAGwAZQBzACIAOwAKAH0ACgA%3D
Expected result
Biome should not complain about useless
else
, if it's anelse if
, because returning early in an if conditional chain is a valid programming approach to minimize the amount of conditional checks and it allows to de-nest if statements, reducing indentation levels and making the code easier to read.Code of Conduct
The text was updated successfully, but these errors were encountered: