fmtquotecheck

module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2024 License: MIT

README

quotecheck

tag Go Version GoDoc Go Lint codecov Report card CodeQL Dependency Review License Latest release GitHub Release Date Last commit PRs Welcome

Verify when safely escape and single quote strings on fmt.Sprintf.

This code is based on perfsprint analyzer.

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

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 ./...

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL