reviewdog / errorformat

Vim's quickfix errorformat implementation in Go
https://reviewdog.github.io/errorformat-playground/
MIT License
108 stars 43 forks source link

refactor: go-vet alert fix. #128

Closed Alt-NoRock closed 1 year ago

Alt-NoRock commented 1 year ago

In go-vet, Fprintln function is not allowed below context:

Alt-NoRock commented 1 year ago

Short Description

I want to add new defined format. In fmts/README.md, we need to go test ./... before PR. but this cmd failed.

My Environment

VSCodeSpace used

$ uname -a
Linux codespaces-0ec3fa 5.15.0-1042-azure #49-Ubuntu SMP Tue Jul 11 17:28:46 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
$ go version
go version go1.20.5 linux/amd64
$ git branch
master

Error Log

add new errorformat test failed by go vet

$ go test ./...
ok      github.com/reviewdog/errorformat        0.008s
# github.com/reviewdog/errorformat/cmd/errorformat
cmd/errorformat/main.go:70:2: fmt.Fprintln call has possible formatting directive %f
cmd/errorformat/main.go:70:2: fmt.Fprintln arg list ends with redundant newline
FAIL    github.com/reviewdog/errorformat/cmd/errorformat [build failed]
ok      github.com/reviewdog/errorformat/fmts   0.120s
ok      github.com/reviewdog/errorformat/writer 0.004s
FAIL

if without go vet, test success.

$ go test -vet=off ./...
ok      github.com/reviewdog/errorformat        0.010s
ok      github.com/reviewdog/errorformat/cmd/errorformat        0.003s
ok      github.com/reviewdog/errorformat/fmts   0.122s
ok      github.com/reviewdog/errorformat/writer 0.004s

Reason of bug and countermeasure.

In usage function, use Fprintf instead of Fprintln. Because usage context includes formatting directive %f:

Example:
    $ echo '/path/to/file:14:28: error message\nfile2:3:4: msg' | errorformat "%f:%l:%c: %m"
review-dog commented 1 year ago

Hi, @Alt-NoRock! We merged your PR to reviewdog! 🐶 Thank you for your contribution! ✨

We just invited you to join the @reviewdog organization on GitHub. Accept the invite by visiting https://github.com/orgs/reviewdog/invitation. By joining the team, you'll be a part of reviewdog community and can help the maintenance of reviewdog.

Thanks again!