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: go vet should issue warning for nonsense json tags #40007

Open
jdef opened this issue Jul 2, 2020 · 3 comments
Open

cmd/vet: go vet should issue warning for nonsense json tags #40007

jdef opened this issue Jul 2, 2020 · 3 comments
Milestone

Comments

@jdef
Copy link

@jdef jdef commented Jul 2, 2020

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

$ go version

go version go1.13.9 linux/amd64

Does this issue reproduce with the latest release?

unsure, not tested

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

go env Output
$ go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE=...redacted
GOENV=...redacted
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=...redacted
GONOSUMDB=...redacted
GOOS="linux"
GOPATH=...redacted
GOPRIVATE=...redacted
GOPROXY=...redacted
GOROOT="/usr/local/go-1.13.9"
GOSUMDB=...redacted
GOTMPDIR=""
GOTOOLDIR="/usr/local/go-1.13.9/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=...redacted
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build172171850=/tmp/go-build -gno-record-gcc-switches"

What did you do?

type Foo struct {
  Bar string `json:"bar:omitempty"`
}
go vet ./...

(no warnings)

What did you expect to see?

vet should warn about a possible typo: s/:omitempty/,omitempty/

What did you see instead?

no warning, just confusing app behavior

@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Jul 2, 2020

bar:omitempty is a valid tag though

package main

import (
	"encoding/json"
	"fmt"
)

type Foo struct {
	B string `json:"bar:omitempty"`
}

type Foo2 struct {
	B string `json:"bar,omitempty"`
}

func main() {
	b := []byte(`{"bar:omitempty": "baz"}`)

	var foo Foo
	json.Unmarshal(b, &foo)
	fmt.Println("with tag:", foo)

	// with "fixed" tag
	var foo2 Foo2
	json.Unmarshal(b, &foo2)
	fmt.Println("with fixed tag:", foo2)
}

outputs

with tag: {baz}
with fixed tag: {}
@jdef
Copy link
Author

@jdef jdef commented Jul 2, 2020

@cagedmantis cagedmantis changed the title go vet should issue warning for nonsense json tags cmd/vet: go vet should issue warning for nonsense json tags Jul 6, 2020
@cagedmantis cagedmantis added this to the Backlog milestone Jul 6, 2020
@cagedmantis
Copy link
Contributor

@cagedmantis cagedmantis commented Jul 6, 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
You can’t perform that action at this time.