go-github icon indicating copy to clipboard operation
go-github copied to clipboard

Use https://staticcheck.io/

Open gauntface opened this issue 3 years ago • 6 comments

I just updated the internal (Google) version of go-github and one of the existing tools flagged some issues that seem reasonable to flag on GitHub.

The tool is staticcheck: https://staticcheck.io/

They look like they have a CLI and GitHub Actions.

Example of the errors it found, on actions_artifacts.go Line 121 there is an unused error value

parsedURL, err := url.Parse(resp.Header.Get("Location"))
return parsedURL, newResponse(resp), nil

@gmlewis and @willnorris curious what you think?

gauntface avatar Jan 21 '22 17:01 gauntface

@gmlewis and @willnorris curious what you think?

Cool find, @gauntface ! Can you create a PR to incorporate it into the GitHub action workflow in this repo? Or I'm happy to work on it if you would prefer.

gmlewis avatar Jan 21 '22 17:01 gmlewis

Curiously, it looks like staticcheck might not work yet with Go 1.18 beta:

$ go version
go version devel go1.18-8ff254e30b Thu Dec 9 19:01:08 2021 +0000 linux/amd64

$ staticcheck ./...
-: cannot import "internal/cpu" (unknown iexport format version 2), export data is newer version - update tool (compile)
-: cannot import "internal/goarch" (unknown iexport format version 2), export data is newer version - update tool (compile)

gmlewis avatar Jan 21 '22 18:01 gmlewis

This looks pretty trivial: https://staticcheck.io/docs/running-staticcheck/github-actions/ I can put together a PR after I clean up the violations if there are no objections.

gmlewis avatar Jan 21 '22 18:01 gmlewis

We already run golangci-lint. We can just enable staticcheck there (https://golangci-lint.run/usage/linters/)

willnorris avatar Jan 21 '22 18:01 willnorris

apparently we explicitly disable staticcheck in https://github.com/google/go-github/blob/master/.golangci.yml, probably because it was failing at the time. What I will typically do with golangci-lint is check in the initial config with failing checks disabled, then do follow-up commits that fix the failures and re-enable the check. We just never did that follow-up here I guess.

willnorris avatar Jan 21 '22 18:01 willnorris

I'll take a stab at cleaning and enabling it later today if no one is working on it.

gauntface avatar Jan 21 '22 19:01 gauntface