diff --git a/README.md b/README.md index 830dc4f..e890ff0 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ linters-settings: Unmarshal and Scan methods are excluded by default as they must use pointer receivers: - `*.UnmarshalText`, `*.UnmarshalJSON`, `*.UnmarshalJSONFrom`, `*.UnmarshalYAML` -- `*.UnmarshalXML`, `*.UnmarshalBinary`, `*.GobDecode`, `*.Scan` +- `*.UnmarshalXML`, `*.UnmarshalBinary`, `*.GobDecode`, `*.UnmarshalMapstructure`, `*.Scan` ## Examples diff --git a/analyzer.go b/analyzer.go index b1d8c3a..c3ba3eb 100644 --- a/analyzer.go +++ b/analyzer.go @@ -18,14 +18,15 @@ func NewAnalyzer(s Settings) *analysis.Analyzer { if !s.DisableBuiltin { // Default excludes for Unmarshal/Decode methods https://github.com/raeperd/recvcheck/issues/17 a.excluded = map[string]struct{}{ - "*.UnmarshalText": {}, - "*.UnmarshalJSON": {}, - "*.UnmarshalJSONFrom": {}, - "*.UnmarshalYAML": {}, - "*.UnmarshalXML": {}, - "*.UnmarshalBinary": {}, - "*.GobDecode": {}, - "*.Scan": {}, + "*.UnmarshalText": {}, + "*.UnmarshalJSON": {}, + "*.UnmarshalJSONFrom": {}, + "*.UnmarshalYAML": {}, + "*.UnmarshalXML": {}, + "*.UnmarshalBinary": {}, + "*.GobDecode": {}, + "*.UnmarshalMapstructure": {}, + "*.Scan": {}, } } @@ -52,6 +53,7 @@ type Settings struct { // - "UnmarshalXML" // - "UnmarshalBinary" // - "GobDecode" + // - "UnmarshalMapstructure" // - "Scan" DisableBuiltin bool diff --git a/testdata/src/builtinmethods/mapstructure.go b/testdata/src/builtinmethods/mapstructure.go new file mode 100644 index 0000000..7dff0f8 --- /dev/null +++ b/testdata/src/builtinmethods/mapstructure.go @@ -0,0 +1,11 @@ +package builtinmethods + +type Mapstructure struct{} + +func (m Mapstructure) String() string { + panic("not implemented") +} + +func (m *Mapstructure) UnmarshalMapstructure(input any) error { + panic("not implemented") +} diff --git a/testdata/src/disablebuiltin/mapstructure.go b/testdata/src/disablebuiltin/mapstructure.go new file mode 100644 index 0000000..ff730fb --- /dev/null +++ b/testdata/src/disablebuiltin/mapstructure.go @@ -0,0 +1,11 @@ +package disablebuiltin + +type Mapstructure struct{} // want `the methods of "Mapstructure" use pointer receiver and non-pointer receiver.` + +func (m Mapstructure) String() string { + panic("not implemented") +} + +func (m *Mapstructure) UnmarshalMapstructure(input any) error { + panic("not implemented") +} diff --git a/testdata/src/disablebuiltin/mapstructure.go.golden b/testdata/src/disablebuiltin/mapstructure.go.golden new file mode 100644 index 0000000..410f672 --- /dev/null +++ b/testdata/src/disablebuiltin/mapstructure.go.golden @@ -0,0 +1,11 @@ +package disablebuiltin + +type Mapstructure struct{} // want `the methods of "Mapstructure" use pointer receiver and non-pointer receiver.` + +func (m *Mapstructure) String() string { + panic("not implemented") +} + +func (m *Mapstructure) UnmarshalMapstructure(input any) error { + panic("not implemented") +}