IDE0010 should not complain about missing default case? #65322
-
Shouldn't IDE0010 be separated into two rules? So that we can disable one and keep the other? This is what IDE0010 checks for: (https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0010) -An enum switch statement that's missing cases for one or more enum members. Problem is, I see no reason for it to complain about missing default case when all the other enum members are already in the switch. I think the rule should either be separated, so people who want default in all their switches can use it, or the rule should not require default case if all the other enum members are in the switch already... The probem with the current behavior is that if I want to have the rule activate in case someone adds something to the enum but forgets to add to the switch, I cannot disable the rule, and if I leave the rule on I cannot reach the default case in unit tests and this leaves the case uncovered on the coverage report. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
"missing default case when all the other enum members are already in the switch" I agree that they should be split however, but it's not irrelevant. |
Beta Was this translation helpful? Give feedback.
"missing default case when all the other enum members are already in the switch"
That's possible when a numeric value has been cast to the enum. .NET does not guarantee that an enum is one of the defined values. I think it may also be possible with mismatched runtime DLLs but I haven't written a POC for it.
I agree that they should be split however, but it's not irrelevant.