Skip to content
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

Removed useless if/else #2939

Merged
merged 4 commits into from
May 27, 2024
Merged

Removed useless if/else #2939

merged 4 commits into from
May 27, 2024

Conversation

KenAJoh
Copy link
Collaborator

@KenAJoh KenAJoh commented May 16, 2024

Description

https://biomejs.dev/linter/rules/no-useless-else/#_top

In the cases where previous if/if else returns/continues one would never be able to reach the next if else/else.

Copy link

changeset-bot bot commented May 16, 2024

⚠️ No Changeset found

Latest commit: b0070aa

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

github-actions bot commented May 16, 2024

Storybook demo

ead4154db | 81 komponenter | 182 stories

JulianNymark
JulianNymark previously approved these changes May 24, 2024
@@ -22,7 +22,9 @@ const ruleFunction: stylelint.Rule = () => {
!deprecation.classes.includes(className.value)
) {
continue;
} else if (
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always thought that these are not 100% equivalent code paths, where the else expressions can "short circuit" if the earlier if condition matches, so they become mutually exclusive, but a bunch of separate ifs could in theory all run? (and their mutual exclusion must be coded inside the conditional itself). I think it's less mental overhead to just have one type of simpler if construct, so I'm absolutely for this change! (I also don't know if this change is 100% legit if it was run by a --fix that might not think about the meaning of the conditional independently vs together? (I haven't double checked all these manually, but if you have when you made this PR, then this is an insta merge 👏 :) ). Future ifs will be handled as they are created / you get a lint error then & there, and refactor code to be simpler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

further reading about the rule, it's only when there's a return or continue or break... etc in the earlier if statement, then the else might always be unnecessary 🤔 ... so I guess this is probably fine then (though the biome page does state this rule has only got an unsafe fix.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes were made manually without the unsafe fix 👍

further reading about the rule, it's only when there's a return or continue or break... etc in the earlier if statement, then the else might always be unnecessary 🤔

Thats what the rule noUselessElse tries to fix 👍 When a if-test has a return/continue etc it will never reach the next step when true. So the following if else can be shortened to if 🙌

@KenAJoh KenAJoh merged commit f23fd9a into main May 27, 2024
3 checks passed
@KenAJoh KenAJoh deleted the biome-noUselessElse branch May 27, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants