-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhancement: [switch-exhaustiveness-check] considerDefaultExhaustiveForUnions
only with comment
#10251
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
Comments
Alternatively, the error could be reported not on the |
I think this is a better idea because if we have to choose between two comment options:
IMO, option (2) is better, if only because most ESLint users are familiar with it. Besides, I'm sure that even if we adopt option (1), most rule users will still put the |
Sorry, I'm not quite wrapping my head around this. Could you elaborate slightly? |
When there are many or long If the comment had been above the |
Ok, I hear what you're saying, but I'm -1 on moving the report location. I don't think you can really safely do any operation to a I think I could just as well say "what if I did a refactoring and removed the first case, which I thought was unused" and didn't see the eslint-disable case all the way down on the My gut says the bug-preventing potential of the report location being on the |
I'm personally -1 as well. I think no matter where you report there are going to be trade-offs. |
The But hey, maybe this is a big useful thing more folks will be asking about now that |
It's been >4 months without any new engagement. The team is still not in favor of growing the rule's complexity in this way. Closing out as wontfix for tseslint. Note that you can always fork and/or rewrite the rule. https://typescript-eslint.io/developers has docs on writing your own rules and plugins. Cheers! 💖 |
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Link to the rule's documentation
https://typescript-eslint.io/rules/switch-exhaustiveness-check/
Description
I like the new default behavior (
considerDefaultExhaustiveForUnions: false
), so that I have to explicitly list every union case in a switch statement. However, sometimes there are really big unions where I'd like to rely on thedefault
case implicitly covering all other cases.I don't want to disable the
switch-exhaustiveness-check
rule with an ESLint comment, because it will likely be missed and kept when changing thedefault
case, given that it has to be above theswitch (…) {
line and not above thedefault:
line and is thus out of sight.Example
Instead, I propose adding a new option value for
considerDefaultExhaustiveForUnions
(and maybe even making it the default instead offalse
):'onlyWithComment'
With this option, a
default
case on its own would still not be considered exhaustive, but adding a comment right before thedefault
case would silence the rule.Example
Fail
Pass
Additional Info
No response
The text was updated successfully, but these errors were encountered: