-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
feat(eslint-plugin): [no-unsafe-enum-comparison] add switch suggestion #7691
Merged
JoshuaKGoldberg
merged 20 commits into
typescript-eslint:main
from
StyleShit:tweak/no-unsafe-enum-comparison-suggestion
Oct 19, 2023
Merged
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0471e12
feat(eslint-plugin): [no-unsafe-enum-comparison] add switch suggestion
StyleShit 930b14a
refactor + add tests
StyleShit b800d1b
remove "void fixer"
StyleShit bbf8156
Merge remote-tracking branch 'typescript-eslint/main' into tweak/no-u…
StyleShit d901495
fix lint
StyleShit 1efbc51
Merge branch 'main' into tweak/no-unsafe-enum-comparison-suggestion
StyleShit b49c446
wip
StyleShit eb577f5
Merge remote-tracking branch 'origin/tweak/no-unsafe-enum-comparison-…
StyleShit 2e7619e
Merge remote-tracking branch 'typescript-eslint/main' into tweak/no-u…
StyleShit 42928a5
beautify
StyleShit 32c3d75
just changing a wrong variable name
StyleShit 3a923ca
just making it look & feel better and consistent
StyleShit a20fe15
add failing test
StyleShit 07f9306
wip
StyleShit f62bd56
Merge remote-tracking branch 'typescript-eslint/main' into tweak/no-u…
StyleShit 9c492f7
added some more tests to cover stupid cases
StyleShit 7ce6387
Merge remote-tracking branch 'typescript-eslint/main' into tweak/no-u…
StyleShit cf56040
moar stupid tests
StyleShit acea5f6
Merge remote-tracking branch 'typescript-eslint/main' into tweak/no-u…
StyleShit 52af550
Merge branch 'main' into tweak/no-unsafe-enum-comparison-suggestion
StyleShit File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -565,5 +565,143 @@ ruleTester.run('strict-enums-comparison', rule, { | |
`, | ||
errors: [{ messageId: 'mismatched' }], | ||
}, | ||
{ | ||
code: ` | ||
enum Str { | ||
A = 'a', | ||
B = 'b', | ||
} | ||
declare const str: Str; | ||
str === 'b'; | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'mismatched', | ||
suggestions: [ | ||
{ | ||
messageId: 'replaceValueWithEnum', | ||
output: ` | ||
enum Str { | ||
A = 'a', | ||
B = 'b', | ||
} | ||
declare const str: Str; | ||
str === Str.B; | ||
`, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
enum Num { | ||
A = 1, | ||
B = 2, | ||
} | ||
declare const num: Num; | ||
1 === num; | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'mismatched', | ||
suggestions: [ | ||
{ | ||
messageId: 'replaceValueWithEnum', | ||
output: ` | ||
enum Num { | ||
A = 1, | ||
B = 2, | ||
} | ||
declare const num: Num; | ||
Num.A === num; | ||
`, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
enum Mixed { | ||
A = 1, | ||
B = 'b', | ||
} | ||
declare const mixed: Mixed; | ||
mixed === 1; | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'mismatched', | ||
suggestions: [ | ||
{ | ||
messageId: 'replaceValueWithEnum', | ||
output: ` | ||
enum Mixed { | ||
A = 1, | ||
B = 'b', | ||
} | ||
declare const mixed: Mixed; | ||
mixed === Mixed.A; | ||
`, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
enum Mixed { | ||
A = 1, | ||
B = 'b', | ||
} | ||
declare const mixed: Mixed; | ||
mixed === 'b'; | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'mismatched', | ||
suggestions: [ | ||
{ | ||
messageId: 'replaceValueWithEnum', | ||
output: ` | ||
enum Mixed { | ||
A = 1, | ||
B = 'b', | ||
} | ||
declare const mixed: Mixed; | ||
mixed === Mixed.B; | ||
`, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
enum StringKey { | ||
'a' = 1, | ||
} | ||
declare const stringKey: StringKey; | ||
stringKey === 1; | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'mismatched', | ||
suggestions: [ | ||
{ | ||
messageId: 'replaceValueWithEnum', | ||
output: ` | ||
enum StringKey { | ||
'a' = 1, | ||
} | ||
declare const stringKey: StringKey; | ||
stringKey === StringKey['a']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Just confirming explicitly in case someone looks at this in the future: I think it's fine to have it look like |
||
`, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[Praise] Great comments, thanks for continuing the existing standard 🙂