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
Allow explicit allowlist mode for switch-case checking #36
Comments
Hi, thanks for the report. I think the proposal is a good one. But also a question: Did you consider using the existing -- Besides that, if we want to go ahead with the proposal, please feel welcome to send a PR! And feel free to use the new comment syntax and the new flag name that you described in the issue. If I'm going to work on it myself, I'm afraid I won't find time in the next 3 weeks. But I can definitely help review a change sooner. |
Yeah, I considered that option. However, after looking at our codebase for a bit, I realize that the prevailing use case for switch statements on enums was to select one or two members. I would really like to adopt this tooling for certain areas of interest like enum mappers which are meant to be highly exhaustive, but it seems harder to convince its use when the opt-out becomes the heavy majority of cases. We also use a Bazel monorepo so it's not something that can be easily decided at the team level. I think there's sort of a "know it when you see it" moment when it comes to uses that are meant to be exhaustive vs those that are not. Usually the not cases where exhaustiveness makes less sense look like boolean expressions like
whereas cases where exhaustiveness makes sense are more like cases similar to implementing a sealed interface in other languages, e.g. I think the setting to allow default to allow exhaustiveness is almost good enough. The problem is that since Go doesn't have true enums, developers may still want to insert
|
Also I'm happy to take this one on. It seems like a relatively simple ask. |
Hello there. This package seems very useful for many use cases in our team's projects. However, in a significant number of cases, switch-case is used as a shorthand for something like
enum == X || enum == Y || enum == Z
, and in most of those cases I don't think exhaustiveness checking is warranted. On the other hand, it would be very useful for situations like enum to enum mappers.Do you think it would be possible to define a separate mode of enforcement which only looks at explicitly labeled "exhaustive switch" blocks? e.g. a
//exhaustive:enforce
comment above switches +-enforcement-mode=explicit
?The text was updated successfully, but these errors were encountered: