SA5008: `json:"-,omitempty"` 结构标签上的假阳性
作者: patjakdev创建于 2026年2月25日更新于 2026年2月25日
标签false-positiveupstream
I have a struct which correctly marshals to and unmarshals from JSON with the following struct tag:
type nodeJSON struct {
// omitted...
Subtract *binaryJSON `json:"-,omitempty"`
// omitted...
}However, since upgrading to staticcheck v0.7.0, I've been getting this false positive:
internal/json/json.go:112:33: should encoding/json ignore this field or name it "-"? Either use `json:"-"` to ignore the field or use `json:"'-',omitempty"` to specify "-" as the name (SA5008)As far as I can tell, there's nothing wrong with the current construction. The suggested fix is new syntax that is only available if using the encoding/json/v2 package, which I am not.
内容来源: dominikh/go-tools