While it seems safe write '%s' to just delimit some string, it may have nasty consequences, like if the string already contains a quote char it add some surprises in our output.
But go supports a better alternative: %q is defined as a single-quoted character literal safely escaped with Go syntax.
Instruction
go install github.com/peczenyj/fmtquotecheck/cmd/fmtquotecheck@latest
Usage
package main
import "fmt"
func main(){
fmt.Printf("hello '%s'", "world") // we should use %q here
}
$ fmtquotecheck ./main.go
./main.go:6:16: explicit single-quoted '%s' should be replaced by `%q` in fmt.Printf
by using the option -fix the linter will convert all '%s' to %q.
CI
CircleCI
- run:
name: install fmtquotecheck
command: go install github.com/peczenyj/fmtquotecheck/cmd/fmtquotecheck@latest
- run:
name: run fmtquotecheck
command: fmtquotecheck ./...
GitHub Actions
- name: install fmtquotecheck
run: go install github.com/peczenyj/fmtquotecheck/cmd/fmtquotecheck@latest
- name: run fmtquotecheck
run: fmtquotecheck ./...