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

cmd/vet: structtag field repeats json warning with valid override #40102

Open
tylfin opened this issue Jul 7, 2020 · 3 comments
Open

cmd/vet: structtag field repeats json warning with valid override #40102

tylfin opened this issue Jul 7, 2020 · 3 comments
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@tylfin
Copy link

tylfin commented Jul 7, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/[XX]/Library/Caches/go-build"
GOENV="/Users/[XX]/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/[XX]/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.1/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/w9/kv18_grs18x65fyzv1p5mvk00000gn/T/go-build893878327=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

When embedding two structs with duplicate JSON tags, e.g.:

type A struct {
   name string `json:"name"`
   ... // additional fields
}

type B struct {
   name string `json:"name"`
   ... // additional fields
}

type C struct {
    A
    B // raises go vet structtag warning
}

A structtag warning is raised by go vet. I think a reasonable workaround to the warning is to override the duplicate-tag on the top level, per extra rules here: https://golang.org/pkg/encoding/json/#Marshal, e.g.

type C struct {
   A
   B
   name string `json:"name"`
}

But go vet still raises the warning.

Note I did add the flag -structtag=false as a workaround but there are cases where I would like to be alerted, but only when no override has been set

What did you expect to see?

go vet treats top-level structtag overrides as a valid solution and no longer raises a warning.

What did you see instead?

go vet ignores the top-level override, resulting in structtag: struct field X repeats json tag "[X]" also at XXXX.go:XXX (govet)

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jul 7, 2020
@gopherbot gopherbot added this to the Unreleased milestone Jul 7, 2020
@tylfin tylfin changed the title x/tools/cmd/vet: structtag field repeats json warning with valid override cmd/vet: structtag field repeats json warning with valid override Jul 7, 2020
@dmitshur
Copy link
Contributor

/cc @alandonovan (per owners) @ianlancetaylor @matloob.

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 11, 2020
@dmitshur dmitshur modified the milestones: Unreleased, Backlog Jul 11, 2020
@adonovan adonovan added the Analysis Issues related to static analysis (vet, x/tools/go/analysis) label Apr 23, 2023
@vedranvuk
Copy link

It does this for the "-" tag as well.

@ahmednawaz10p
Copy link

any update on this ?

epavlova added a commit to Financial-Times/content-tree that referenced this issue Feb 2, 2024
The representation is semi-automatically generated from the
JSON schema rules for the content tree.
The Go vet linter fails due to golang/go#40102
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

6 participants