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: warn about more malformed JSON struct tags #37210

Open
pfwgbe opened this issue Feb 13, 2020 · 1 comment
Open

cmd/vet: warn about more malformed JSON struct tags #37210

pfwgbe opened this issue Feb 13, 2020 · 1 comment
Milestone

Comments

@pfwgbe
Copy link

@pfwgbe pfwgbe commented Feb 13, 2020

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

$ go version
go version go1.13.4 darwin/amd64

Does this issue reproduce with the latest release?

Yes, the problem appears with 1.13.8 as well.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/XYZ/Library/Caches/go-build"
GOENV="/Users/XYZ/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB="example.com/*"
GOOS="darwin"
GOPATH="/Users/XYZ/go"
GOPRIVATE=""
GOPROXY="http://proxy.example.com"
GOROOT="/Users/XYZ/go/go1.13.4"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/XYZ/go/go1.13.4/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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/fm/6cbjfz6s33qbxn77r5lt89cc0000gp/T/go-build495195143=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I ran go vet on the following code:

package main

import (
	"fmt"
	"encoding/json"
)

type S struct {
	Foo int `json:"fnord.foo"`
}

func main() {
	data := []byte(`
		{
			"fnord": {
				"foo": 1
			}
		}
	`)

	var s S
	err := json.Unmarshal(data, &s)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%#v\n", s)
}

What did you expect to see?

I expected go vet to warn me about the undecodable parts of the struct, with something like "encoding/json does not support dot-separated paths"

What did you see instead?

go vet did not print any output and had a zero exit value, indicating that there are no problems with the code.

@josharian josharian changed the title cmd/vet should warn about malformed struct tags for JSON decoding cmd/vet: warn about more malformed JSON struct tags Feb 13, 2020
@josharian

This comment has been minimized.

Copy link
Contributor

@josharian josharian commented Feb 13, 2020

Seems reasonable. Should fit nicely into the existing vet struct tags check. Should be pretty straightforward to implement for anyone wanting to try their hand on vet.

cc @mvdan @robpike

@dmitshur dmitshur added this to the Backlog milestone Feb 15, 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.