verify when safely escape and single quote strings on fmt.Sprintf
Motivation
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
CI
CircleCI
- run:
name: install ttempdir
command: go install github.com/peczenyj/fmtquotecheck/cmd/fmtquotecheck@latest
- run:
name: run ttempdir
command: ttempdir ./...
GitHub Actions
- name: install ttempdir
run: go install github.com/peczenyj/fmtquotecheck/cmd/fmtquotecheck@latest
- name: run ttempdir
run: ttempdir ./...