Skip to content

fix: Exclude UnmarshalMapstructure by default - #59

Closed
fedorkanin wants to merge 1 commit into
raeperd:mainfrom
fedorkanin:fk/exclude-unmarshal-mapstructure
Closed

fedorkanin wants to merge 1 commit into
raeperd:mainfrom
fedorkanin:fk/exclude-unmarshal-mapstructure

Conversation

@fedorkanin

@fedorkanin fedorkanin commented Dec 3, 2026 •

Copy link
Copy Markdown

Add UnmarshalMapstructure to the default exclusions.

go-viper/mapstructure defines the Unmarshaler interface.
It is used by Viper, a popular configuration library, to decode config values into custom types.

Like the other Unmarshal* methods, UnmarshalMapstructure must use a pointer receiver because it writes to its receiver.
Value types that implement it, such as enums decoded from config strings, often keep value receivers for their other methods (String, MarshalText, etc.).
These types are currently reported as mixed receivers, which is a false positive for the same reason as #17.

mapstructure's Unmarshaler, used by Viper to decode configuration,
must use a pointer receiver, the same as the other Unmarshal methods.
Value types that implement it were reported as mixed receivers.
@raeperd

raeperd commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR and the clear explanation. I agree UnmarshalMapstructure needs a pointer receiver.

That said, I'm going to decline this. The default exclusions aren't meant to track interfaces from 3rd party libraries. If I add mapstructure, I'd also have to consider every other decoder that defines its own Unmarshal* method, and keeping that list up to date isn't something I want to take on.

You can exclude it in your own config instead:

linters-settings:
  recvcheck:
    exclusions:
      - "*.UnmarshalMapstructure"

Thanks again for taking the time on this.

@raeperd raeperd closed this Dec 4, 2026
@fedorkanin

Copy link
Copy Markdown
Author

Makes sense! Thanks for taking a look

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

Successfully merging this pull request may close these issues.

2 participants