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
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.
Milestone

Comments

@jdef
Copy link

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
Member

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 commented Jul 2, 2020 via email

@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 cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 6, 2020
@cagedmantis
Copy link
Contributor

/cc @alandonovan

@adonovan adonovan added the Analysis Issues related to static analysis (vet, x/tools/go/analysis) label Apr 23, 2023
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.
Projects
None yet
Development

No branches or pull requests

4 participants