Skip to content

U1000: field is unused #1360

@Dreamacro

Description

@Dreamacro

staticcheck version: staticcheck 2023.1 (v0.4.0)
go version: go version go1.19.5 darwin/arm64

PoC:

package main

import (
	"github.com/phuslu/log"
)

type Log struct {
	Time      string `json:"time"`
	Level     string `json:"level"`
	Caller    string `json:"-"`
	Goid      string `json:"-"`
	Stack     string `json:"-"`
	Message   string `json:"message"`
	KeyValues []struct {
		Key       string `json:"key"`
		Value     string `json:"value"`
		ValueType byte   `json:"-"`
	} `json:"fields"`
}

//	type FormatterArgs struct {
//		Time      string // "2019-07-10T05:35:54.277Z"
//		Level     string // "info"
//		Caller    string // "prog.go:42"
//		Goid      string // "123"
//		Stack     string // "<stack string>"
//		Message   string // "a structure message"
//		KeyValues []struct {
//			Key       string // "foo"
//			Value     string // "bar"
//			ValueType byte   // 's'
//		}
//	}
type Event = log.FormatterArgs

func main() {
	e := Event{}
	l := Log(e)

	log.Info().Msgf("log: %+v", l)
}

staticcheck output:

/Users/dreamacro/go/pkg/mod/github.com/phuslu/log@v1.0.83/formatter.go:13:1: field Time is unused (U1000)
/Users/dreamacro/go/pkg/mod/github.com/phuslu/log@v1.0.83/formatter.go:14:1: field Level is unused (U1000)
/Users/dreamacro/go/pkg/mod/github.com/phuslu/log@v1.0.83/formatter.go:15:1: field Caller is unused (U1000)
/Users/dreamacro/go/pkg/mod/github.com/phuslu/log@v1.0.83/formatter.go:16:1: field Goid is unused (U1000)
/Users/dreamacro/go/pkg/mod/github.com/phuslu/log@v1.0.83/formatter.go:17:1: field Stack is unused (U1000)
/Users/dreamacro/go/pkg/mod/github.com/phuslu/log@v1.0.83/formatter.go:18:1: field Message is unused (U1000)
/Users/dreamacro/go/pkg/mod/github.com/phuslu/log@v1.0.83/formatter.go:19:1: field KeyValues is unused (U1000)

FormatterArgs does not have the required json format, so a structure with the same but json fields is set. It is used for http response.

I think this is a false positive.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions