go-simpler / musttag

🚔 Enforce field tags in (un)marshaled structs
https://go-simpler.org/musttag
Mozilla Public License 2.0
36 stars 9 forks source link

Possible false positive #98

Closed davidnewhall closed 4 months ago

davidnewhall commented 4 months ago

I might be missing something, but this looks like a false positive to me. Is there some way I can fix this? Thanks!

Output

[david@dns-mm2]14:00:42|/Volumes/Storage/david/go/src/github.com/Notifiarr/notifiarr$ golangci-lint run ./...
pkg/configfile/config.go:110:26: the given struct should be annotated with the `toml` tag (musttag)
    if _, err := dec.Decode(&newConfig); err != nil {
                            ^
pkg/website/clientinfo/clientinfo.go:179:49: the given struct should be annotated with the `json` tag (musttag)
    if err = json.Unmarshal(body.Details.Response, &clientInfo); err != nil {
                                                   ^
[david@dns-mm2]14:01:01|/Volumes/Storage/david/go/src/github.com/Notifiarr/notifiarr$

Same thing in a screenshot:

Screenshot 2024-07-21 at 2 04 31 PM

Code

The links go directly to the affected lines on GitHub.

tmzane commented 4 months ago

Hey, thanks for the detailed report.

From config.go:

I think it complains about LogConfig.AppName not having the toml tag.

From clientinfo.go:

And here the problem is with MySQLConfig fields missing the json tag.

Am I missing something here? Please let me know.

I can see why it might be hard to get the exact reason with many struct layers without field name hints, sorry for the inconvenience. We're about to add a verbose mode in #89, which will print the names of the untagged fields.

davidnewhall commented 4 months ago

Thank you for the detailed analysis. I've could swear I've seen musttag complain directly with the line number for the struct missing tags. This behavior was unexpected. I'll add the missing tags you found and report back if this goes away.

+1 to hints or struct/struct member names.

davidnewhall commented 4 months ago

Indeed you found the problem and fixing it makes the lint warning go away. Thanks so much!