Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat(eslint-plugin): [no-unsafe-enum-comparison] handles switch cases#7541
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Thanks for the PR,@Zamiell! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently onhttps://opencollective.com/typescript-eslint. |
netlifybot commentedAug 26, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
✅ Deploy Preview fortypescript-eslint ready!
To edit notification comments on pull requests, go to yourNetlify site configuration. |
nx-cloudbot commentedAug 26, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Zamiell commentedAug 26, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Oh, interestingly enough, the new version of the rule found a bug atpackages/eslint-plugin/src/rules/no-unnecessary-type-constraint.ts. (Well, CI passes except for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Great stuff, thanks for such a thorough look & overhaul! 🔥
A few requests for changes, and some nitpicks I'd like to hear your thoughts on.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
Uh oh!
There was an error while loading.Please reload this page.
Zamiell commentedSep 18, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
theres some bogus stuff going on in CI, i think a maintainer needs tolook at this, as it looks unrelated to my PR. |
JoshuaKGoldberg left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Oop, I'd meant to merge changes frommain
after merging#7691 but I don't think I have permissions to push to your branch@Zamiell. Pushed to here instead:https://github.com/JoshuaKGoldberg/typescript-eslint/tree/enum-comparison-switch-merge
Ithink the lint failure inErrorsViewer.tsx
on theswitch (severity)
is an existing bug in the rule that just so happens to be exposed by this PR. Something imported withimport type
might not be a value that can actually be runtime-imported. If this is an existing bug, I think it'd be reasonable toeslint-disable
it in this PR and file a followup issue. WDYT?
Otherwise 👍 LGTM for merging! We'd want to file a followup issue to get#7691'ssuggest: ...
in switch statements too.
how do i give you permission? otherwise, just merge whatever changes from your own branch, as it doesn't matter to me |
JoshuaKGoldberg commentedOct 22, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
It's on the bottom-right of the page, at the bottom of the right sidebar: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork is the closest docs page I could find on docs.github.com. I would prefer to get the changes in this PR so that it's easier to find from the Git history. And you deserve direct/primary author attribution as you've put a lot of great work into this PR! 😄 |
@JoshuaKGoldberg That button doesn't show up for me. Can you just use the changes from your own branch instead? |
JoshuaKGoldberg commentedNov 11, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Sure, no worries:#7898. I'm guessing you're not seeing the permissions because this PR was sent from an organization ( |
ok, should i close this PR now? |
JoshuaKGoldberg commentedNov 13, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
PR Checklist
switch
statements #7509Overview
Hello, co-author of the
no-unsafe-enum-comparison
rule here.Currently, he
no-unsafe-enum-comparison
rule handles comparisons (e.g.BinaryExpression
) but it does not handle switch statements. My PR makes the rule handle both.This was an oversight in my original design of this rule, and I consider this to be a bug. However, I have marked the PR as
feat
instead offix
to be more conservative; feel free to change it if you wish.Code Change Summary
I refactored the logic in the
BinaryExpression
selector and put it inside of a function calledisMismatchedComparison
.Then, I can call that function from multiple selectors. The changes should be pretty straightforward to understand.
Other Notes
I have reworked the documentation for this rule a bit, as the original text is now no longer accurate, because TypeScript has made number enums more safe in version 5.0. Thus, I rewrote the document to focus on the string case, adding a line to emphasize that the rule is still useful if you choose to use string enums over number enums.