Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
peczenyj authored Jun 10, 2024
1 parent ffd334e commit d749737
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,70 @@
# quotecheck

[![tag](https://img.shields.io/github/tag/peczenyj/fmtquotecheck.svg)](https://github.com/peczenyj/fmtquotecheck/releases)
![Go Version](https://img.shields.io/badge/Go-%3E%3D%201.21-%23007d9c)
[![GoDoc](https://pkg.go.dev/badge/github.com/peczenyj/fmtquotecheck)](http://pkg.go.dev/github.com/peczenyj/fmtquotecheck)
[![Go](https://github.com/peczenyj/fmtquotecheck/actions/workflows/go.yml/badge.svg)](https://github.com/peczenyj/fmtquotecheck/actions/workflows/go.yml)
[![Lint](https://github.com/peczenyj/fmtquotecheck/actions/workflows/lint.yml/badge.svg)](https://github.com/peczenyj/fmtquotecheck/actions/workflows/lint.yml)
[![codecov](https://codecov.io/gh/peczenyj/fmtquotecheck/graph/badge.svg?token=9y6f3vGgpr)](https://codecov.io/gh/peczenyj/fmtquotecheck)
[![Report card](https://goreportcard.com/badge/github.com/peczenyj/fmtquotecheck)](https://goreportcard.com/report/github.com/peczenyj/fmtquotecheck)
[![CodeQL](https://github.com/peczenyj/fmtquotecheck/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/peczenyj/fmtquotecheck/actions/workflows/github-code-scanning/codeql)
[![Dependency Review](https://github.com/peczenyj/fmtquotecheck/actions/workflows/dependency-review.yml/badge.svg)](https://github.com/peczenyj/fmtquotecheck/actions/workflows/dependency-review.yml)
[![License](https://img.shields.io/github/license/peczenyj/fmtquotecheck)](./LICENSE)
[![Latest release](https://img.shields.io/github/release/peczenyj/fmtquotecheck.svg)](https://github.com/peczenyj/fmtquotecheck/releases/latest)
[![GitHub Release Date](https://img.shields.io/github/release-date/peczenyj/fmtquotecheck.svg)](https://github.com/peczenyj/fmtquotecheck/releases/latest)
[![Last commit](https://img.shields.io/github/last-commit/peczenyj/fmtquotecheck.svg)](https://github.com/peczenyj/fmtquotecheck/commit/HEAD)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/peczenyj/fmtquotecheck/blob/main/CONTRIBUTING.md#pull-request-process)

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](https://pkg.go.dev/fmt) as `a single-quoted character literal safely escaped with Go syntax.`

## Instruction

```sh
go install github.com/peczenyj/fmtquotecheck/cmd/fmtquotecheck@latest
```

## Usage

```go
package main

import "fmt"

func main(){
fmt.Printf("hello '%s'", "world") // we should use %q here
}
```

```console
$ fmtquotecheck ./main.go
./main.go:6:16: explicit single-quoted '%s' should be replaced by `%q` in fmt.Printf
```

## CI

### CircleCI

```yaml
- run:
name: install ttempdir
command: go install github.com/peczenyj/fmtquotecheck/cmd/fmtquotecheck@latest

- run:
name: run ttempdir
command: ttempdir ./...
```
### GitHub Actions
```yaml
- name: install ttempdir
run: go install github.com/peczenyj/fmtquotecheck/cmd/fmtquotecheck@latest

- name: run ttempdir
run: ttempdir ./...
```

0 comments on commit d749737

Please sign in to comment.