feat: add go checker group - #23
Merged
Merged
Conversation
One hook covers Go formatting, linting, and module tidiness: `golangci-lint fmt`, `golangci-lint run`, and `go mod tidy -diff`. golangci-lint has no PyPI wrapper and upstream discourages `go install`, so the hook downloads the pinned 2.13.2 release tarball on first use into `sys.prefix/polymath-go`. That directory belongs to the pre-commit-managed virtualenv, so the download is scoped to one hook revision, shared across every consuming repo on the machine, and never lands in a consuming repo's tree. The tarball is verified against a sha256 pinned in source for each of the four supported platforms, taken from the release's own checksums file, so trusting the download costs no second network fetch. An exclusive flock serializes the install, since pre-commit runs one hook over several batches of files in parallel. Downloading a binary at first use has precedent here: hadolint-py and shellcheck-py do the same at install time. The Go toolchain itself stays a prerequisite. golangci-lint type-checks by compiling, so bundling a binary would not remove the requirement, and any repo with a go.mod already has developers with Go installed. When `go` is absent the group returns a single failed result pointing at go.dev/dl, ahead of the pile of downstream noise a missing compiler produces. The linter set is golangci-lint's `standard` default (errcheck, govet, ineffassign, staticcheck, unused) plus errorlint, misspell, revive, and unconvert, with gofumpt and goimports as formatters. Polymath has no internal Go precedent to inherit, so this follows community practice. Adding linters later is a minor version bump. golangci-lint works on packages and must run from a module root, so staged files are grouped by their nearest ancestor go.mod and collapsed to package directories, each group run with cwd at its module root. `run()` gains an optional `cwd` for this. The config sets `run.relative-path-mode: wd`, since golangci-lint's default renders reported paths relative to the config file, and this config ships inside the hook's virtualenv. Vendored sources are dropped from the grouping. `run` on a vendored package dir exits 7 with "not a package listed in vendor/modules.txt", and `fmt` would rewrite third-party code the consumer cannot fix. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Emerson Knapp <emerson@polymathrobotics.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.
One hook covers Go formatting, linting, and module tidiness:
golangci-lint fmt,golangci-lint run, andgo mod tidy -diff.golangci-lint has no PyPI wrapper and upstream discourages
go install, so the hook downloads the pinned 2.13.2 release tarball on first use intosys.prefix/polymath-go.That directory belongs to the pre-commit-managed virtualenv, so the download is scoped to one hook revision, shared across every consuming repo on the machine, and never lands in a consuming repo's tree.
The tarball is verified against a sha256 pinned in source for each of the four supported platforms, taken from the release's own checksums file, so trusting the download costs no second network fetch.
An exclusive flock serializes the install, since pre-commit runs one hook over several batches of files in parallel. Downloading a binary at first use has precedent here: hadolint-py and shellcheck-py do the same at install time.
The Go toolchain itself stays a prerequisite. golangci-lint type-checks by compiling, so bundling a binary would not remove the requirement, and any repo with a go.mod already has developers with Go installed. When
gois absent the group returns a single failed result pointing at go.dev/dl, ahead of the pile of downstream noise a missing compiler produces.The linter set is golangci-lint's
standarddefault (errcheck, govet, ineffassign, staticcheck, unused) plus errorlint, misspell, revive, and unconvert, with gofumpt and goimports as formatters. Polymath has no internal Go precedent to inherit, so this follows community practice. Adding linters later is a minor version bump.golangci-lint works on packages and must run from a module root, so staged files are grouped by their nearest ancestor go.mod and collapsed to package directories, each group run with cwd at its module root.
run()gains an optionalcwdfor this. The config setsrun.relative-path-mode: wd, since golangci-lint's default renders reported paths relative to the config file, and this config ships inside the hook's virtualenv.Vendored sources are dropped from the grouping.
runon a vendored package dir exits 7 with "not a package listed in vendor/modules.txt", andfmtwould rewrite third-party code the consumer cannot fix.