Repository navigation
Conversation
amoeba
left a comment
There was a problem hiding this comment.
Thanks. This ended up being a nice tour of how Go has changed over the versions.
I had a question about the setup. It looks like golangci-lint is designed to run either locally or in CI but not easily both. See comment above.
| - id: golangci-lint | ||
| entry: bash -c 'golangci-lint run --fix --timeout 5m' | ||
| types_or: [go, go-mod] |
There was a problem hiding this comment.
I had a few questions here:
- golangci-lint defines
types: [go]which I think gets ANDed so does specifying types_or like this work? - I don't think the go.mod linters are enabled by default anyway
I went back and forth a bit to try to figure out something that,
- Runs the normal golangci-lint on staged files
- Runs on all files in CI
Have you had to do this before? I came up with:
| - id: golangci-lint | |
| entry: bash -c 'golangci-lint run --fix --timeout 5m' | |
| types_or: [go, go-mod] | |
| - id: golangci-lint | |
| args: [--timeout=5m] | |
| - id: golangci-lint-full # just for ci | |
| args: [--timeout=5m] | |
| stages: [manual] |
- editing dev.yml to run the manual stage too.
There was a problem hiding this comment.
Hmm, this is what we do for all our drivers, and it seems to work fine. We already run pre-commit run --all-files so there's no need for golangci-lint-full
There was a problem hiding this comment.
TBH, there's not much point for "run only on staged files", because changes in one file can cause lints in unchanged files.
| key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} | ||
|
|
||
| - name: Run pre-commit | ||
| run: pre-commit run --all-files --color=always --show-diff-on-failure --verbose |
There was a problem hiding this comment.
| run: pre-commit run --all-files --hook-stage manual --color=always --show-diff-on-failure --verbose | |
| env: | |
| SKIP: golangci-lint |
|
CI failure looks like a real race or something. I'll see if I can't figure it out. |
It seems to be fixed on re-run. |
zeroshade
left a comment
There was a problem hiding this comment.
Looks good overall. The code changes are mechanical lint fixes, and I checked the ones that rewrite conditions (diagnosticURLEnd, validArchiveSHA256, registryHash): each is a correct De Morgan rewrite.
Pre-commit hook
- Use
golangci-lint-fullinstead of thebash -cwrapper. The upstreamgolangci-linthook runsgolangci-lint run --new-from-rev HEAD --fix, so it only reports new problems. Thebash -centry here replaces that with exactly what the upstreamgolangci-lint-fullhook already does (golangci-lint run --fix,pass_filenames: false). Simpler, and it doesn't need bash:That lints the whole module on every run, which matches the point that a change in one file can cause lints in others. No- id: golangci-lint-full args: [--timeout=5m]
manualstage orSKIPis needed, since CI already runs--all-files. types_or: [go, go-mod]does nothing extra. The upstream hook setstypes: [go], and pre-commit combinestypesandtypes_orwith AND, so a commit that only changesgo.modwon't trigger the linter locally. Either drop the line or override withtypes: [file]plus afiles:pattern.
Nits
auth.go:authLoginCompleteMsg(msg)converts one struct type straight into another, which only compiles while the two have identical fields. Adding a field to either one breaks the build somewhere unrelated.authLoginCompleteMsg{cred: msg.cred}was clearer.- The fixes leave
var source = httptest.NewServer(...)(andvar archive = ...) where:=is the normal Go style. - For the govet
inlineanalyzer turned off as "broken in go 1.27", please link the upstream issue so it's clear when it can be turned back on. A tracking issue for turningerrcheck,staticcheckandunusedback on would also help.
amoeba
left a comment
There was a problem hiding this comment.
I'm good with this as is. I tested that this does what I think it should do locally both with a normal pre-commit hook as well as the --all-files variant we run in CI. Re: @zeroshade's comments, I'm somewhere between indifferent and preferring just to accept what the linter did for those ones.
Thanks for this @lidavidm.
PS: The test failure should is a flake and should be addressed by #586.
Many of the linters are disabled for now because they require more extensive changes to fix.
|
I rebased and made some tweaks; any objections? |
Fixes the failing `Run pre-commit hooks` job on main (https://github.com/columnar-tech/dbc/actions/runs/44146064069). #575 merged after #583 enabled golangci-lint with `--fix`, and its CI ran before that, so the modernizer rewrite of `errors.As` to `errors.AsType` in `checkDownloadedArchive` was never applied. This is the hook's own output. Verified locally: `pre-commit run --all-files` passes, `go build ./...` and `go test ./cmd/dbc/` pass.
Many of the linters are disabled for now because they require more extensive changes to fix.
Closes #582.