Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Go Report Card #217

Closed
siggy opened this issue Jan 26, 2018 · 10 comments
Closed

Improve Go Report Card #217

siggy opened this issue Jan 26, 2018 · 10 comments

Comments

@siggy
Copy link
Member

siggy commented Jan 26, 2018

We are getting an A+ on Go Report Card, but there is still a lot to improve:
https://goreportcard.com/report/github.com/runconduit/conduit
https://goreportcard.com/report/github.com/linkerd/linkerd2

We should consider these changes, and also add a badge to README.md.

@klingerf
Copy link
Contributor

Hmm, looks like almost all of the issues in the repo could be found with the golint tool. We should get in the habit of running that.

@pcalcado
Copy link
Contributor

Should we create a precommit.sh file or something that does a standardized go test ./... && go vet ./... && golint? Also could be the script travis runs

@klingerf
Copy link
Contributor

Yeah, I'd be in favor of auto-running some form of linting, but I'd like to investigate if the linting rules are configurable before we start failing builds. There are a few things turned up by the linter that don't seem important to me, such as:

var mockApiClient should be mockAPIClient

@klingerf
Copy link
Contributor

Heh, and this one:

func name will be used as version.VersionFlag by other packages, and that stutters; consider calling this Flag

@pcalcado
Copy link
Contributor

I am very easygoing with these things, I can definitely live with the silly ones if it gives us a standardised and well-supported way to check for more interesting things.

@rafaeljesus
Copy link

IMHO I am not really about skipping these lint errors, it's pretty handy for writing idiomatic golang code ^.^

Also it might be required if you decide to add it at awesome-go list

siggy added a commit that referenced this issue Dec 22, 2018
Part of #217. Follow up from #1982 and #2018.

A subsequent commit will fix the ci failure.

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Jan 2, 2019
Commit 1: Enable lint check for comments

Part of #217. Follow up from #1982 and #2018.

A subsequent commit will fix the ci failure.

Commit 2: Address all comment-related linter errors.

This change addresses all comment-related linter errors by doing the
following:
- Add comments to exported symbols
- Make some exported symbols private
- Recommend via TODOs that some exported symbols should should move or
  be removed

This PR does not:
- Modify, move, or remove any code
- Modify existing comments

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 9, 2019
`ineffassign` detects ineffectual assignments in Go code. This change
introduces a `bin/ineffassign` into ci, and fixes 4 ineffectual
assignments caught by ineffassign.

Also perform a one-time gofmt cleanup:
- `gofmt -s -w controller/`
- `gofmt -s -w pkg/`

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 9, 2019
`ineffassign` detects ineffectual assignments in Go code. This change
introduces a `bin/ineffassign` into ci, and fixes 4 ineffectual
assignments caught by ineffassign.

Also perform a one-time gofmt cleanup:
- `gofmt -s -w controller/`
- `gofmt -s -w pkg/`

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 13, 2019
`golangci-lint` performs numerous checks on Go code, including golint,
ineffassign, govet, and gofmt.

This change modifies `bin/lint` to use `golangci-lint`, and replaces
usage of golint and govet.

Also perform a one-time gofmt cleanup:
- `gofmt -s -w controller/`
- `gofmt -s -w pkg/`

Part of #217
siggy added a commit that referenced this issue Feb 13, 2019
`golangci-lint` performs numerous checks on Go code, including golint,
ineffassign, govet, and gofmt.

This change modifies `bin/lint` to use `golangci-lint`, and replaces
usage of golint and govet.

Also perform a one-time gofmt cleanup:
- `gofmt -s -w controller/`
- `gofmt -s -w pkg/`

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 13, 2019
`golangci-lint` performs numerous checks on Go code, including golint,
ineffassign, govet, and gofmt.

This change modifies `bin/lint` to use `golangci-lint`, and replaces
usage of golint and govet.

Also perform a one-time gofmt cleanup:
- `gofmt -s -w controller/`
- `gofmt -s -w pkg/`

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
@siggy
Copy link
Member Author

siggy commented Feb 18, 2019

Taking this a bit further, #2284 introduced a .golangci.yml file, which specifies which golangci-lint checkers to run.

To help improve the codebase further, we should work towards reducing the number of checkers in the disable list. Essentially repeat this pattern:

  1. remove an item from the disable list
  2. run bin/lint, observe errors
  3. fix errors until bin/lint succeeds

siggy added a commit that referenced this issue Feb 23, 2019
gosimple is a Go linter that specializes in simplifying code

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 23, 2019
gosimple is a Go linter that specializes in simplifying code

Also fix one spelling error in `cred_test.go`

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 23, 2019
gosimple is a Go linter that specializes in simplifying code

Also fix one spelling error in `cred_test.go`

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 23, 2019
`unused` checks Go code for unused constants, variables, functions, and
types.

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 23, 2019
`unused` checks Go code for unused constants, variables, functions, and
types.

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 23, 2019
`varcheck` finds unused global variables and constants. Our repo was
already passing so no fixes needed.

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 23, 2019
`deadcode` finds unused code.
`varcheck` finds unused global variables and constants.

Our repo was already passing both linters so no fixes needed.

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 23, 2019
Enables the following linters:
- `deadcode` finds unused code.
- `depguard` checks if package imports are in a list of acceptable
  packages.
- `misspell` finds commonly misspelled English words in comments.
- `nakedret` finds naked returns in functions greater than a specified
  function length.
- `varcheck` finds unused global variables and constants.

Our repo was already passing these linters so no fixes needed.

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 23, 2019
Enables the following linters:
- `deadcode` finds unused code.
- `depguard` checks if package imports are in a list of acceptable
  packages.
- `misspell` finds commonly misspelled English words in comments.
- `nakedret` finds naked returns in functions greater than a specified
  function length.
- `varcheck` finds unused global variables and constants.

Our repo was already passing these linters so no fixes needed.

Also explicitly list all linters enabled by default, for reference.

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 23, 2019
Enables the following linters:
- `deadcode` finds unused code.
- `depguard` checks if package imports are in a list of acceptable
  packages.
- `misspell` finds commonly misspelled English words in comments.
- `nakedret` finds naked returns in functions greater than a specified
  function length.
- `varcheck` finds unused global variables and constants.

Our repo was already passing these linters so no fixes needed.

Also explicitly list all linters enabled by default, for reference.

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 24, 2019
goimports checks import lines, adding missing ones and removing
unreferenced ones:
https://godoc.org/golang.org/x/tools/cmd/goimports

It also requires named imports for packages whose
import paths don't match their package names:
- golang/go#28428
- https://go-review.googlesource.com/c/tools/+/145699/

Also standardized named imports of common Kubernetes packaages.

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 24, 2019
goconst finds repeated strings that could be replaced by a constant:
https://github.com/jgautheron/goconst

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 24, 2019
interlacer suggests narrower interface types:
https://github.com/mvdan/interfacer

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 24, 2019
interfacer suggests narrower interface types:
https://github.com/mvdan/interfacer

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 24, 2019
unconvert removes unnecessary type conversions:
https://github.com/mdempsky/unconvert

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 24, 2019
unparam reports unused function parameters:
https://github.com/mvdan/unparam

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 25, 2019
goconst finds repeated strings that could be replaced by a constant:
https://github.com/jgautheron/goconst

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 25, 2019
goimports checks import lines, adding missing ones and removing
unreferenced ones:
https://godoc.org/golang.org/x/tools/cmd/goimports

It also requires named imports for packages whose
import paths don't match their package names:
- golang/go#28428
- https://go-review.googlesource.com/c/tools/+/145699/

Also standardized named imports of common Kubernetes packaages.

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 25, 2019
goimports checks import lines, adding missing ones and removing
unreferenced ones:
https://godoc.org/golang.org/x/tools/cmd/goimports

It also requires named imports for packages whose
import paths don't match their package names:
- golang/go#28428
- https://go-review.googlesource.com/c/tools/+/145699/

Also standardized named imports of common Kubernetes packaages.

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 26, 2019
unconvert removes unnecessary type conversions:
https://github.com/mdempsky/unconvert

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 26, 2019
interfacer suggests narrower interface types:
https://github.com/mvdan/interfacer

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 26, 2019
unparam reports unused function parameters:
https://github.com/mvdan/unparam

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 26, 2019
interfacer suggests narrower interface types:
https://github.com/mvdan/interfacer

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 26, 2019
unparam reports unused function parameters:
https://github.com/mvdan/unparam

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 27, 2019
unparam reports unused function parameters:
https://github.com/mvdan/unparam

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
siggy added a commit that referenced this issue Feb 27, 2019
unparam reports unused function parameters:
https://github.com/mvdan/unparam

Part of #217

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
@grampelberg
Copy link
Contributor

@siggy this issue doesn't feel particularly actionable at this point (and there's a ton of awesome work that's already been done). WDYT about closing this out and opening up directed issues for what's remaining?

@siggy
Copy link
Member Author

siggy commented Dec 18, 2019

@grampelberg I'm fine with closing this one.

Note that we lost our perfect gofmt score recently:
https://goreportcard.com/report/github.com/linkerd/linkerd2#gofmt
This may have happened when we changed our lint config, probably worth a new issue to track this.

@grampelberg
Copy link
Contributor

I was wondering about that. Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants