cmd/vet: make printf checking more precise when arguments are changed #26555
Labels
Milestone
Comments
Change https://golang.org/cl/125039 mentions this issue: |
gopherbot
pushed a commit
that referenced
this issue
Jul 23, 2018
Fixes #26486 Updates #26555 Change-Id: I402137b796e574e9b085ab54290d1b4ef73d3fcc Reviewed-on: https://go-review.googlesource.com/125039 Reviewed-by: Russ Cox <rsc@golang.org>
It seems to me like this would require the use of more advanced tooling in vet, such as the use of |
I've seen an issue with the following code which now fails vet in v1.11: func Say(expected string, args ...interface{}) *sayMatcher {
formattedRegexp := expected
if len(args) > 0 {
formattedRegexp = fmt.Sprintf(expected, args...)
}
return &sayMatcher{
re: regexp.MustCompile(formattedRegexp),
}
} Re-writing like this allows it to pass vet, but this seems like a very fragile "fix". func Say(expected string, args ...interface{}) *sayMatcher {
if len(args) > 0 {
expected = fmt.Sprintf(expected, args...)
}
return &sayMatcher{
re: regexp.MustCompile(expected),
}
} Ideally |
blgm
added a commit
to onsi/gomega
that referenced
this issue
Sep 6, 2018
- go vet in Go v1.11 identifies `Say()` as a print wrapper - go vet will then fail for `Say("%")` because this is not a valid Sprintf template - Because of golang/go#26486, changing the way that the functon is written will work around the vet issue - I have added a comment documenting that this is not ideal in golang/go#26555 (comment)
nodo
added a commit
to onsi/gomega
that referenced
this issue
Sep 10, 2018
- go vet in Go v1.11 identifies `Say()` as a print wrapper - go vet will then fail for `Say("%")` because this is not a valid Sprintf template - Because of golang/go#26486, changing the way that the functon is written will work around the vet issue - I have added a comment documenting that this is not ideal in golang/go#26555 (comment)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For #26486 https://golang.org/cl/125039 changed the printf checking to only warn about functions that do not modify the arguments before passing them to
fmt.Printf
(or whatever). The example in that issue, drawn from real code, is:This can be called as
dbg("", err)
.The fix in CL 125039 means that we no longer issue printf warnings for functions like this:
We should figure out a way to continue issuing warnings for
Prefix
without issuing them fordbg
.The text was updated successfully, but these errors were encountered: