go vet configuration? to check variant of printf having to do with verbs

86 views
Skip to first unread message

gocss

unread,
Jul 26, 2022, 10:02:19 AM7/26/22
to golang-nuts
Is there a way to configure 'go vet' to a variant of sprintf/printf that I rolled

such

loopErrMsgf := func(format string, params ...interface{}) string {
             errCnt++
             return fmt.Sprintf("[checkIn:loopCnt:%d, errCnt:%d] error %s", loopCnt, errCnt, fmt.Sprintf(format, params...))
         }   

that will flag if params does not include correct corresponding printf verbs that are
passed in 'format' ??? above?

If not 'go vet" I used but yet to remember tool I have done this with in the past,
is there another way to do such checks?

gocss

unread,
Jul 26, 2022, 10:39:06 AM7/26/22
to golang-nuts
Appears 'go vet -printf.funcs loopErrMsgf'
does not detect incorrect verbs or lack thereof on anonymous functions ... :(
as shown above, which is my desired use case.

gocss

unread,
Jul 26, 2022, 11:03:01 AM7/26/22
to golang-nuts
also found this so it is a known limitation:

Brian Candler

unread,
Jul 26, 2022, 12:15:40 PM7/26/22
to golang-nuts
Instead of a closure, could you put loopCnt and errCnt in a struct, and then make your loopErrMsg be a method on that?
Reply all
Reply to author
Forward
0 new messages