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

Comments

@jech
Copy link

@jech 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 this to the Unplanned milestone Dec 22, 2020
@mdempsky
Copy link
Member

@mdempsky mdempsky commented Dec 22, 2020

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

@laojianzi laojianzi commented Dec 23, 2020

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

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Dec 23, 2020

Yep, thanks.

@mdempsky mdempsky closed this Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants