Skip to content
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

Anonymous structs should not be checked for exhaustiveness #62

Closed
navijation opened this issue Jul 4, 2023 · 4 comments
Closed

Anonymous structs should not be checked for exhaustiveness #62

navijation opened this issue Jul 4, 2023 · 4 comments

Comments

@navijation
Copy link
Contributor

In my experience, the most common use case for an anonymous struct is in unit test case loops. These should not typically be exhaustive-enforced because many fields are omitted by default to improve the brevity of the test case, e.g. test writers do not always want to specify expectErr: false everywhere.

Exhaustruct's current behavior on anonymous structs will be prohibitive for many if not most company codebases, including all the ones I've worked on in the past.

For backwards compatibility, this behavior should be configured with a flag.

navijation pushed a commit to navijation/go-exhaustruct that referenced this issue Jul 4, 2023
@xobotyi
Copy link
Collaborator

xobotyi commented Jul 15, 2023

There is no need in separate flag, we already have exclusion list - so the only requied thing is to allow matching anonymous structures by <anonymous> alias

@ImprintNav
Copy link

Not introducing the flag is backwards incompatible in the sense that code that would fail the linter before will now start to pass. If that's not a concern then that's fine.

@xobotyi
Copy link
Collaborator

xobotyi commented Jul 17, 2023

@ImprintNav how is that? #65 only adds ability to exclude\include anonymous tags, without changing overall behaviour. anonymous structures are linted as it was before the change.

@xobotyi xobotyi closed this as completed Jul 17, 2023
@navijation
Copy link
Contributor Author

@xobotyi What I meant was that code which would have failed at the time due to anonymous structs would start to succeed after #65. e.g. with the following config

i:
  - i.Included

This configuration before #65 would fail on a repo with non-exhaustive anonymous structs because the old implementation always barred anonymous structs, but in the new interpretation, this same config would not include anonymous struct literals. If a repo actually intended for this behavior, upgrading would lead to silent loss of analyzer coverage when new anonymous struct literals are added.

I agree this is sublte and unlikely, however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants