Make the golangci-lint settings take effect: v2 config layout, linter pinned at v2.12.2 (closes #10)
check / check (push) Successful in 3m32s

golangci-lint v2 ignores a top-level linters-settings block without a
warning, so limits such as the 88-column line length were never
applied. .golangci.yml is now the canonical copy from sneak/prompts,
verbatim, which keeps its settings under linters.settings and also
configures depguard and gomodguard_v2. golangci-lint is pinned at
v2.12.2 by commit in the Dockerfile and script/bootstrap. The long
lines in attrsum.go are rewrapped and one nolint directive moves to
its own line; behaviour is unchanged.

Model: opus-5-5
This commit was merged in pull request #4.
This commit is contained in:
2026-10-06 03:26:51 +02:00
parent 6a0dfa9f2c
commit 30b36dabe4
5 changed files with 169 additions and 75 deletions
+80 -14
View File
@@ -1,32 +1,98 @@
version: "2" version: "2"
# Config schema uses the golangci-lint v2 layout (settings live under
# linters.settings, not top-level linters-settings) so that the
# thresholds below are actually applied by golangci-lint >= v2.
run: run:
timeout: 5m timeout: 5m
modules-download-mode: readonly modules-download-mode: readonly
linters: linters:
default: all default: all
enable:
# Successor to the deprecated gomodguard. Named explicitly, rather than
# left to `default: all`, because it carries the module policy below.
- gomodguard_v2
disable: disable:
# Genuinely incompatible with project patterns # Genuinely incompatible with project patterns
- exhaustruct # Requires all struct fields - exhaustruct # Requires all struct fields
- depguard # Dependency allow/block lists
- godot # Requires comments to end with periods - godot # Requires comments to end with periods
- wsl # Deprecated, replaced by wsl_v5
- wrapcheck # Too verbose for internal packages - wrapcheck # Too verbose for internal packages
- varnamelen # Short names like db, id are idiomatic Go - varnamelen # Short names like db, id are idiomatic Go
# Deprecated: the warning is attached to the old name, so it is
linters-settings: # silenced by disabling that name, not by enabling the successor.
lll: - wsl # Deprecated, replaced by wsl_v5
line-length: 88 - gomodguard # Deprecated, replaced by gomodguard_v2
funlen: settings:
lines: 80 lll:
statements: 50 line-length: 88
cyclop: funlen:
max-complexity: 15 lines: 80
dupl: statements: 50
threshold: 100 cyclop:
max-complexity: 15
dupl:
threshold: 100
depguard:
# Test-support code must not be compiled into the shipped binary. A
# test-support package exists to hand a test privileges the program
# itself must never have, so a file that is not a test must not import
# one. Test files, and the files inside a package whose directory name
# ends in `test`, are where that code belongs, and are exempt.
#
# The deny list below is the one part of this file a repository is
# expected to extend, and the only part it may. depguard matches an
# import path against a list of prefixes, so it cannot be told "any path
# whose last segment ends in test"; a repository's own test-support
# packages have to be named here one at a time, by full import path,
# under a module path that differs from repository to repository. Add
# them; change nothing else.
rules:
test-support:
list-mode: lax
files:
- "$all"
- "!$test"
- "!**/*test/**"
deny:
- pkg: net/http/httptest
desc: >-
Test-support code belongs in test files and in packages whose
directory name ends in test, not in the shipped binary.
# Only decisions already recorded in the Go package defaults are
# listed here. Every entry matches the module path exactly.
gomodguard_v2:
blocked:
- module: github.com/rs/zerolog
recommendations:
- log/slog
reason: "Structured logging is stdlib log/slog."
# One entry per pre-fork module path, because the later releases
# are separate paths. A prefix match would be shorter but would
# also reach github.com/go-redis/redismock, the test double for
# the successor these entries recommend.
- module: github.com/go-redis/redis
recommendations:
- github.com/redis/go-redis/v9
reason: "Pre-fork module; use the maintained go-redis v9."
- module: github.com/go-redis/redis/v7
recommendations:
- github.com/redis/go-redis/v9
reason: "Pre-fork module; use the maintained go-redis v9."
- module: github.com/go-redis/redis/v8
recommendations:
- github.com/redis/go-redis/v9
reason: "Pre-fork module; use the maintained go-redis v9."
- module: github.com/sergi/go-diff
recommendations:
- github.com/aymanbagabas/go-udiff
reason: "No unified diff output; use go-udiff."
- module: github.com/hexops/gotextdiff
recommendations:
- github.com/aymanbagabas/go-udiff
reason: "Unmaintained fork; use go-udiff."
issues: issues:
exclude-use-default: false
max-issues-per-linter: 0 max-issues-per-linter: 0
max-same-issues: 0 max-same-issues: 0
+2 -2
View File
@@ -4,8 +4,8 @@ FROM golang@sha256:f6751d823c26342f9506c03797d2527668d095b0a15f1862cddb4d927a7a4
RUN apk add --no-cache git make gcc musl-dev binutils-gold RUN apk add --no-cache git make gcc musl-dev binutils-gold
# golangci-lint v2.10.1 # golangci-lint v2.12.2, 2026-10-05
RUN go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@5d1e709b7be35cb2025444e19de266b056b7b7ee RUN go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@c0d3ddc9cf3faa61a4e378e879ece580256d76e5
# goimports v0.42.0 # goimports v0.42.0
RUN go install golang.org/x/tools/cmd/goimports@009367f5c17a8d4c45a961a3a509277190a9a6f0 RUN go install golang.org/x/tools/cmd/goimports@009367f5c17a8d4c45a961a3a509277190a9a6f0
+5
View File
@@ -24,6 +24,11 @@ today) with lint, fmt, fmt-check, check, and hooks targets.
# Completed Steps # Completed Steps
* 2026-10-05: golangci-lint settings take effect: canonical
`.golangci.yml` (v2 layout, settings under `linters.settings`),
golangci-lint pinned at v2.12.2 in `Dockerfile` and
`script/bootstrap`, and the code fixed for what the settings now
report (long lines in `attrsum.go` rewrapped)
* 2026-10-05: `make try` runs on three small files in a temporary * 2026-10-05: `make try` runs on three small files in a temporary
directory that it removes afterwards, also when a step fails, directory that it removes afterwards, also when a step fails,
instead of on a fixed directory on one person's machine instead of on a fixed directory on one person's machine
+79 -56
View File
@@ -76,7 +76,8 @@ func (s *Stats) Print(opts *options, operation string) {
return return
} }
fmt.Fprintf(os.Stderr, "\n%s complete: %d files processed, %d skipped, %d failed, %s bytes in %s\n", fmt.Fprintf(os.Stderr,
"\n%s complete: %d files processed, %d skipped, %d failed, %s bytes in %s\n",
operation, operation,
s.FilesProcessed, s.FilesProcessed,
s.FilesSkipped, s.FilesSkipped,
@@ -171,11 +172,15 @@ func expandPaths(args []string) ([]string, error) {
} }
// processFunc processes a single path within a command's run loop. // processFunc processes a single path within a command's run loop.
type processFunc func(opts *options, path string, stats *Stats, bar *progressbar.ProgressBar) error type processFunc func(
opts *options, path string, stats *Stats, bar *progressbar.ProgressBar,
) error
// countAndBar counts the files under paths and returns a progress bar sized // countAndBar counts the files under paths and returns a progress bar sized
// to that total. It always returns either a non-nil bar or a non-nil error. // to that total. It always returns either a non-nil bar or a non-nil error.
func countAndBar(opts *options, paths []string, desc string) (*progressbar.ProgressBar, error) { func countAndBar(
opts *options, paths []string, desc string,
) (*progressbar.ProgressBar, error) {
total, err := countFilesMultiple(opts, paths) total, err := countFilesMultiple(opts, paths)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -193,7 +198,9 @@ func finishBar(bar *progressbar.ProgressBar) {
// runOverPaths runs process over each path, sharing the progress/stats // runOverPaths runs process over each path, sharing the progress/stats
// bookkeeping common to the sum-add, sum-update and clear commands. // bookkeeping common to the sum-add, sum-update and clear commands.
func runOverPaths(opts *options, args []string, desc, op string, process processFunc) error { func runOverPaths(
opts *options, args []string, desc, op string, process processFunc,
) error {
paths, err := expandPaths(args) paths, err := expandPaths(args)
if err != nil { if err != nil {
return err return err
@@ -258,46 +265,54 @@ func newSumCmd(opts *options) *cobra.Command {
return cmd return cmd
} }
func processSumAdd(opts *options, dir string, stats *Stats, bar *progressbar.ProgressBar) error { func processSumAdd(
return walkAndProcess(opts, dir, stats, bar, func(p string, info os.FileInfo, s *Stats) error { opts *options, dir string, stats *Stats, bar *progressbar.ProgressBar,
if hasXattr(p, checksumKey) { ) error {
atomic.AddInt64(&s.FilesSkipped, 1) return walkAndProcess(opts, dir, stats, bar,
func(p string, info os.FileInfo, s *Stats) error {
if hasXattr(p, checksumKey) {
atomic.AddInt64(&s.FilesSkipped, 1)
return nil return nil
} }
err := writeChecksumAndTime(opts, p, info, s) err := writeChecksumAndTime(opts, p, info, s)
if err != nil { if err != nil {
atomic.AddInt64(&s.FilesFailed, 1)
return err
}
return nil
})
}
func processSumUpdate(opts *options, dir string, stats *Stats, bar *progressbar.ProgressBar) error {
return walkAndProcess(opts, dir, stats, bar, func(p string, info os.FileInfo, s *Stats) error {
t, err := readSumTime(p)
if err != nil || info.ModTime().After(t) {
werr := writeChecksumAndTime(opts, p, info, s)
if werr != nil {
atomic.AddInt64(&s.FilesFailed, 1) atomic.AddInt64(&s.FilesFailed, 1)
return werr return err
} }
return nil return nil
} })
atomic.AddInt64(&s.FilesSkipped, 1)
return nil
})
} }
func writeChecksumAndTime(opts *options, path string, info os.FileInfo, stats *Stats) error { func processSumUpdate(
opts *options, dir string, stats *Stats, bar *progressbar.ProgressBar,
) error {
return walkAndProcess(opts, dir, stats, bar,
func(p string, info os.FileInfo, s *Stats) error {
t, err := readSumTime(p)
if err != nil || info.ModTime().After(t) {
werr := writeChecksumAndTime(opts, p, info, s)
if werr != nil {
atomic.AddInt64(&s.FilesFailed, 1)
return werr
}
return nil
}
atomic.AddInt64(&s.FilesSkipped, 1)
return nil
})
}
func writeChecksumAndTime(
opts *options, path string, info os.FileInfo, stats *Stats,
) error {
// Record mtime before hashing to detect modifications during hash. // Record mtime before hashing to detect modifications during hash.
mtimeBefore := info.ModTime() mtimeBefore := info.ModTime()
@@ -368,24 +383,27 @@ func newClearCmd(opts *options) *cobra.Command {
} }
} }
func processClear(opts *options, dir string, stats *Stats, bar *progressbar.ProgressBar) error { func processClear(
return walkAndProcess(opts, dir, stats, bar, func(p string, info os.FileInfo, s *Stats) error { opts *options, dir string, stats *Stats, bar *progressbar.ProgressBar,
cleared, err := clearOne(opts, p) ) error {
if err != nil { return walkAndProcess(opts, dir, stats, bar,
atomic.AddInt64(&s.FilesFailed, 1) func(p string, info os.FileInfo, s *Stats) error {
cleared, err := clearOne(opts, p)
if err != nil {
atomic.AddInt64(&s.FilesFailed, 1)
return err return err
} }
if cleared { if cleared {
atomic.AddInt64(&s.FilesProcessed, 1) atomic.AddInt64(&s.FilesProcessed, 1)
atomic.AddInt64(&s.BytesProcessed, info.Size()) atomic.AddInt64(&s.BytesProcessed, info.Size())
} else { } else {
atomic.AddInt64(&s.FilesSkipped, 1) atomic.AddInt64(&s.FilesSkipped, 1)
} }
return nil return nil
}) })
} }
// clearOne removes both checksum xattrs from a single path, reporting // clearOne removes both checksum xattrs from a single path, reporting
@@ -433,7 +451,8 @@ func newCheckCmd(opts *options) *cobra.Command {
return runCheck(opts, a, cont) return runCheck(opts, a, cont)
}, },
} }
cmd.Flags().BoolVar(&cont, "continue", false, "continue after errors and report each file") cmd.Flags().BoolVar(&cont, "continue", false,
"continue after errors and report each file")
return cmd return cmd
} }
@@ -477,13 +496,16 @@ func runCheck(opts *options, args []string, cont bool) error {
return finalErr return finalErr
} }
func processCheck(opts *options, dir string, cont bool, stats *Stats, bar *progressbar.ProgressBar) error { func processCheck(
opts *options, dir string, cont bool, stats *Stats, bar *progressbar.ProgressBar,
) error {
// Track initial failed count to detect failures during this walk. // Track initial failed count to detect failures during this walk.
initialFailed := atomic.LoadInt64(&stats.FilesFailed) initialFailed := atomic.LoadInt64(&stats.FilesFailed)
err := walkAndProcess(opts, dir, stats, bar, func(p string, _ os.FileInfo, s *Stats) error { err := walkAndProcess(opts, dir, stats, bar,
return checkOne(opts, p, cont, s) func(p string, _ os.FileInfo, s *Stats) error {
}) return checkOne(opts, p, cont, s)
})
if err != nil { if err != nil {
if errors.Is(err, errVerification) { if errors.Is(err, errVerification) {
return errVerification return errVerification
@@ -747,7 +769,8 @@ func hasXattr(path, key string) bool {
func fileMultihash(path string) ([]byte, int64, error) { func fileMultihash(path string) ([]byte, int64, error) {
// The path is supplied by the operator as the tree to checksum; reading // The path is supplied by the operator as the tree to checksum; reading
// it is the entire purpose of the tool. // it is the entire purpose of the tool.
f, err := os.Open(path) //nolint:gosec // G304: operator-specified path is the intended input //nolint:gosec // G304: operator-specified path is the intended input
f, err := os.Open(path)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
} }
+3 -3
View File
@@ -9,9 +9,9 @@ set -eu
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)" ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
# Pinned versions, 2026-07-07 (same pins as the Dockerfile) # Pinned versions, 2026-10-05 (same pins as the Dockerfile)
# golangci-lint v2.10.1 # golangci-lint v2.12.2
GOLANGCI_LINT_REF="github.com/golangci/golangci-lint/v2/cmd/golangci-lint@5d1e709b7be35cb2025444e19de266b056b7b7ee" GOLANGCI_LINT_REF="github.com/golangci/golangci-lint/v2/cmd/golangci-lint@c0d3ddc9cf3faa61a4e378e879ece580256d76e5"
# goimports v0.42.0 # goimports v0.42.0
GOIMPORTS_REF="golang.org/x/tools/cmd/goimports@009367f5c17a8d4c45a961a3a509277190a9a6f0" GOIMPORTS_REF="golang.org/x/tools/cmd/goimports@009367f5c17a8d4c45a961a3a509277190a9a6f0"