-
Notifications
You must be signed in to change notification settings - Fork 225
golangci-lint spring cleaning and bump #997
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
golangci-lint spring cleaning and bump #997
Conversation
Commit a970d99 contains retract directive, which is only supported since Go 1.16. Bump go directive to match that. Also, the current code can no longer be compiled with Go 1.15 anyway (for example, because of filepath.WalkDir usage which is added in Go 1.16). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Error checking is important. In these two cases, though, we don't have a way to return an error, so make it explicit that we ignore the error. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Where we can check the error, do it. Where we can not, ignore it. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
> libimage/manifests/manifests.go:408:3: S1033: unnecessary guard around call to delete (gosimple)
> if _, needToDelete := l.instances[instanceDigest]; needToDelete {
> ^
Indeed, we can just call delete right away.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Fix a couple of warnings like this one: > pkg/formats/templates.go:23:14: SA1019: strings.Title is deprecated: > The rule Title uses for word boundaries does not handle Unicode > punctuation properly. Use golang.org/x/text/cases instead. > (staticcheck) This is caused by the fact that Go 1.18 strings package made a (somewhat strange) decision to deprecate strings.Title. The suggestion to replace it with a new package is a bit too much. Silence the warning instead, as we are pretty sure this function works for us. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
gofumpt is a stricter version of gofmt, basically making the code more readable, and fixing the gocritic's octalLiterar warnings like this one: pkg/util/util_supported.go:26:17: octalLiteral: use new octal literal style, 0o722 (gocritic) return (perm & 0722) == 0700 ^ Generated by gofumpt -w . Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This one:
pkg/manifests/manifests.go:75:1: paramTypeCombine: func(manifestDigest digest.Digest, manifestSize int64, manifestType, osName, architecture, osVersion string, osFeatures []string, variant string, features []string, annotations []string) error could be replaced with func(manifestDigest digest.Digest, manifestSize int64, manifestType, osName, architecture, osVersion string, osFeatures []string, variant string, features, annotations []string) error (gocritic)
func (l *list) AddInstance(manifestDigest digest.Digest, manifestSize int64, manifestType, osName, architecture, osVersion string, osFeatures []string, variant string, features []string, annotations []string) error {
^
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This one:
libimage/manifests/manifests.go:387:10: elseif: can replace 'else {if cond {}}' with 'else if cond {}' (gocritic)
} else {
^
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Like this one: pkg/manifests/manifests.go:449:4: importShadow: shadow of imported from 'github.com/containers/image/v5/manifest' package 'manifest' (gocritic) manifest, err := json.Marshal(&l.oci) ^ First, this is not always a "manifest" (sometimes it's OCI image index). Second, using two variables (manifest and manifestBytes) is not needed. Finally, rename manifest to res (stands for result). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This removes the questionable Sys().(*syscall.Stat_t) typecast. OTOH we have to handle EINTR, so it's a tad more complicated than it should be. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This one: libnetwork/netavark/ipam_test.go:45:22: Error return value is not checked (errcheck) networkInterface = libpodNet.(*netavarkNetwork) ^ Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1. Greatly simplify the golangci-lint config.
1.1. Remove the skip-dir list (of excluded directories), since as all
the issues are now fixed).
1.2. Instead of enabling all the linters and then disabling many of
them, go with the default set of enabled linters, and then add some
(currently just gocritic and dupl).
This will hopefully make upgrading golangci-lint easier, as it
maintains a sensitive set of linters enabled by default (and
enabling all linters by default means we will enable some new and
unknown linters when we bump golangci-lint version).
1.3. Remove the gocritic list of enabled linters, use a default one.
The motivation is similar -- it is hard to maintain/upgrade otherwise.
1.4. Remove the "check-blank: true" option from the errcheck linter, as
we often use _ = fn() type of assignment to denote that we want to
ignore the error.
2. Simplify golangci-lint installation from the Makefile.
3. Bump golangci-lint to 1.45.2.
NOTE that if you are using golangci-lint locally, you have to remove it
from the build directory (i.e. rm -f build/golangci-lint) before running
"make validate").
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
vrothberg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
LGTM other than the nit.
@containers/podman-maintainers PTAL
When the "nolint:gocritic" hint is removed, gocritic says:
pkg/timetype/timestamp.go:37:2: ifElseChain: rewrite if-else to switch statement (gocritic)
if strings.Contains(value, ".") {
^
Indeed, it makes sense to do so.
Rewrite the code, remove the nolint:golint.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Those were added by commit 39a8401, but are apparently no longer needed. Reported-by: Paul Holzinger <pholzing@redhat.com> Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
feafbd0 to
88414bb
Compare
|
No longer a draft. I took a liberty to add a GHA CI job for golangci-lint (while it adds some duplication, it is very fast and whoever opens a PR will know if there are issues in a minute, not half an hour). |
1267395 to
0a93c9c
Compare
This is currently similar to what make validate does in .cirrus.yml, but let's have it as a separate job since it it faster. Let's keep the same job in Cirrus CI for now. Note we do not ping Go version, but rather depend on action/setup-go to know which one is latest. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
And fix the found warnings: pkg/config/systemd.go:61:3: S1023: redundant `return` statement (gosimple) return ^ pkg/config/systemd.go:85:3: S1023: redundant `return` statement (gosimple) return ^ Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
0a93c9c to
0e669c0
Compare
| lint: | ||
| runs-on: ubuntu-20.04 | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - uses: actions/setup-go@v3 | ||
| with: | ||
| go-version: 1.x # latest stable | ||
| - name: install deps | ||
| run: | | ||
| sudo apt-get -qq update | ||
| sudo apt-get -qq install libseccomp-dev libdevmapper-dev | ||
| - name: lint | ||
| uses: golangci/golangci-lint-action@v3 | ||
| with: | ||
| version: "${{ env.LINT_VERSION }}" | ||
| - name: validate seccomp | ||
| run: ./tools/validate_seccomp.sh ./pkg/seccomp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already run this as part of the normal cirrus job so this is redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I am aware of that (this is where I copied the code from). I guess I did that since I was thinking about removing this step (running the linter) from the cirrus job (but have not done it yet).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets do this in a separate PR
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: kolyshkin, rhatdan The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Thanks for the cleanups, @kolyshkin ! |
This
TODO (not in this PR, just ideas)