ci: replace the vet and gofmt steps with a golangci-lint job - #193
Merged
Conversation
CI ran `gofmt -l apps` and `go vet ./...`. golangci-lint's default set includes govet, and its gofmt formatter reports formatting, so both steps are redundant and are removed; lint is one job, checked once. The formatting check also gets wider. `gofmt -l apps` looked at two of the repo's nineteen packages; cli/, test/ and tools/ were never checked. The linter covers all of them, and names the `acceptance` build tag so those files are loaded too. One real bug fixed. tarGzDir deferred Close on the tar writer, the gzip writer and the file, discarding all three errors. The tar trailer and gzip footer are written during those Closes, after the return value is set, so a failure there produced a truncated archive reported as a successful export. Closes now run innermost-first through a named return that keeps the first error. The other 30 unchecked errors were already benign and are now explicit: read handles, error-path cleanup where a failure is already being returned, and SSH teardown. errcheck excludes fmt.Fprint and deferred os.RemoveAll of a temp dir alongside the existing entries. ST1005 is off, with the reason in the config: it wants error strings without trailing punctuation, which fits errors meant to be wrapped, not a CLI's top-level messages written as full sentences on purpose. The staticcheck `checks` list repeats golangci-lint's own default exclusions, because naming only "all" silently re-enables ST1000/ST1003/ST1016/ST1020/ST1021/ST1022 and buries real findings in doc-comment noise. Three golangci-lint defaults that drop findings are disabled: max-issues-per-linter, max-same-issues and uniq-by-line. Signed-off-by: Tim Smith <tim@mondoo.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CI ran
gofmt -l appsandgo vet ./..., with no real linter. This addsgolangci-linton its default set (errcheck,govet,ineffassign,staticcheck,unused) as a required job and removes both steps, since golangci-lint subsumes them. Lint is one job, and nothing is checked twice.The formatting check gets much wider
gofmt -l appscovered 2 of this repo's 19 packages. Everything undercli/,test/andtools/was never formatting-checked. The linter covers all of them, and names theacceptancebuild tag so those files load too. (Therace/!racepair incli/policyfile/rubyevalis inherently one-or-the-other and follows the default build, exactly asgo vetdid.)One real bug
tarGzDirincli/policyfile/export.go:The tar trailer and the gzip footer are written during those Closes, which run after the return value is already set. So a failure while finalising the archive was discarded entirely and
tarGzDirreturnednil— a truncated or corrupt policyfile export reported as success. Closes now run innermost-first through a named return that keeps the first error.Worth a close look, as it is the one behavioural change in the PR.
The other 30 unchecked errors were fine
They fall into three groups, all now explicit rather than silent: read handles (
os.Open+gzip.NewReader), error-path cleanup where a failure is already being returned, and SSH teardown incli/remote. The success paths were already correct — e.g.keys.goand every extraction loop already doif err := f.Close(); err != nil.errcheckadditionally excludesfmt.Fprintand deferredos.RemoveAllof a temp dir.Two config subtleties worth knowing
ST1005 is off, with the reason recorded in
.golangci.yml. It wants error strings without trailing punctuation, which is right for errors meant to be wrapped; these are the CLI's top-level user-facing messages, written as full sentences on purpose ("can't find your client key at %s — it's set as client_key in %s. Create the key file, or update client_key to point at the right path."). Flattening them to satisfy a library convention would make the tool worse.The
checkslist repeats golangci-lint's own defaults. Writing just["all", "-ST1005"]silently re-enables ST1000/ST1003/ST1016/ST1020/ST1021/ST1022, which golangci-lint excludes by default. That took findings from 11 to 60 of mostly doc-comment noise before I caught it.Also disabled:
max-issues-per-linter(50),max-same-issues(3) anduniq-by-line(only the first issue per line) — three defaults that silently drop findings from what is meant to be a blocking gate.Verification
golangci-lint run ./...reports 0 issues.go vet ./...,gofmt -l .,go build ./apps/cincand the fullgo test -race ./...suite all pass, includingcli/policyfile, which covers the changed export path.