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
ElseCaseInsteadOfExhaustiveWhen config to fail when there's only one unused type/value #5623
Comments
I somehow disagree with this. Having a The whole point about not using Do you have some examples to share? |
I have a bunch that all follow the same pattern; a when that checks one or more possible cases, but less than For example using kotlinx json, I have a lot of whens that look like:
In that example an I know I could do:
but that's a lot more mental parsing now. And kotlinx json only had a few cases. What if there were 20 unhandled cases that all get handled the same way? For example, I have a sealed class that models API errors where's there's a
Now I could (and probably should) introduce a hierarchy with a top level
I actually agree with this very strongly, but it doesn't always work in practice. I wish Kotlin would've added an |
This feels to me like either:
|
The later seems more reasonable. I have a few hundred occurrences of this, and local suppression wouldn't be an option because of that. |
We're happy to receive a PR implementing this 🙏 |
…unused type/value detekt#5623 A new `ignoredSubjectTypes` property with an empty default value was introduced. It can be configured with a list of subject types fully qualified names which should be ignored by the `ElseCaseInsteadOfExhaustiveWhen` rule.
Hi, |
A new `ignoredSubjectTypes` property with an empty default value was introduced. It can be configured with a list of subject types fully qualified names which should be ignored by the `ElseCaseInsteadOfExhaustiveWhen` rule.
A new `ignoredSubjectTypes` property with an empty default value was introduced. It can be configured with a list of subject types fully qualified names which should be ignored by the `ElseCaseInsteadOfExhaustiveWhen` rule.
A new `ignoredSubjectTypes` property with an empty default value was introduced. It can be configured with a list of subject types fully qualified names which should be ignored by the `ElseCaseInsteadOfExhaustiveWhen` rule.
I tried enabling ElseCaseInsteadOfExhaustiveWhen but I had way too many violations, and most of them were intentional (e.g. there's a Result type that has Success type and a bunch of failure types, and I only want to know if it was a success or failure, and don't care about the specific failure).
However, I found a few cases where I intended to use an exhaustive when, but I either missed a type, or didn't handle null, and used else instead.
I think it would be helpful if there was a config (or separate rule) that would allow an else in a when, unless there was only one more type that has to be handled (or null).
The text was updated successfully, but these errors were encountered: