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: unnecessary diagnostics about json:"-" on unexported fields #43196

Closed
jech opened this issue Dec 15, 2020 · 3 comments
Closed

cmd/vet: unnecessary diagnostics about json:"-" on unexported fields #43196

jech opened this issue Dec 15, 2020 · 3 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@jech
Copy link

jech commented Dec 15, 2020

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

$ go version
go version go1.15.6 linux/amd64

What did you do?

I like to write code such as the following:

type description struct {
	fileName       string              `json:"-"`
	loadTime       time.Time           `json:"-"`
	modTime        time.Time           `json:"-"`
	fileSize       int64               `json:"-"`
	Description    string              `json:"description,omitempty"`
        ...
}

The unexported fields have a json:"-" tag, so that the resulting behaviour doesn't change if I happen to export the fields later. Unfortunately, this causes go vet warning:

group/group.go:567:2: struct field fileName has json tag but is not exported

There is apparently no way to disable this warning without disabling all JSON-related checks. Please disable the warning in the particular case of a json:"-" tag, or at least provide a way to disable it without disabling all JSON-related checks.

What did you expect to see?

go vet doesn't warn about json:"-" tags on unexported fields, only about non-trivial json tags.

What did you see instead?

go vet complains, and there is no way to avoid the warning short of disabling all JSON-related checking.

@mdempsky mdempsky changed the title go vet complains about json:"-" on unexported fields cmd/vet: unnecessary diagnostics about json:"-" on unexported fields Dec 22, 2020
@mdempsky mdempsky added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Dec 22, 2020
@mdempsky mdempsky added this to the Unplanned milestone Dec 22, 2020
@mdempsky
Copy link
Member

I think it's fine to suppress a warning about json:"-" on unexported fields, since they're not an issue per se.

@laojianzi
Copy link

I think the change has been made in golang/tools@73b12ca

@mdempsky
Copy link
Member

Yep, thanks.

@golang golang locked and limited conversation to collaborators Dec 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants