Skip to content

Apply go fix - #162

Merged
umputun merged 2 commits into
masterfrom
go-fix
Aug 20, 2026
Merged

umputun merged 2 commits into
masterfrom
go-fix

Conversation

@paskal

@paskal paskal commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Output of go fix ./... on Go 1.26, where the command now runs the modernizer analysers. It rewrites strings.HasPrefix and strings.TrimPrefix pairs into strings.CutPrefix, sort.Slice into slices.Sort, counted loops into for range n, strings.Fields into strings.FieldsSeq, string accumulation into strings.Builder, and the per-test context.WithCancel pairs into t.Context().

It also drops omitempty from the two struct-typed fields of bot.Message. The option has never had an effect there: encoding/json treats only false, 0, nil pointers, nil interfaces and empty arrays, slices, maps and strings as empty, so a struct is always encoded. The marshalled form of the message log written in app/reporter/reporter.go and read back in app/reporter/export.go is byte for byte the same, and existing logs still parse. The alternative rewrite go fix offers here, replacing omitempty with omitzero, would change behaviour and is deliberately not applied.

The strings.Builder rewrites left two WriteString(fmt.Sprintf(...)) calls that staticcheck reports as QF1012, so those are written as fmt.Fprintf instead. Tests and golangci-lint are clean on the branch.

`go fix` in Go 1.26 runs the modernizer analysers, so it rewrites
`strings.HasPrefix`/`TrimPrefix` pairs into `strings.CutPrefix`,
`sort.Slice` into `slices.Sort`, counted `for` loops into `for range n`,
`strings.Fields` into `strings.FieldsSeq`, string accumulation into
`strings.Builder`, and per-test contexts into `t.Context()`.

It also drops `omitempty` from the two struct-typed fields of
`bot.Message`, where the option has never had any effect: encoding/json
treats only false, 0, nil pointers and empty arrays, slices, maps and
strings as empty, so a struct is always encoded. The marshalled form of
the message log written in `app/reporter/reporter.go` and read back in
`app/reporter/export.go` is unchanged, and existing logs still parse.
The alternative `omitzero` rewrite, which would change behaviour, is
deliberately not applied.

The `strings.Builder` rewrites left two `WriteString(fmt.Sprintf(...))`
calls that staticcheck flags as QF1012; they are written as
`fmt.Fprintf` instead.
@paskal
paskal requested a review from umputun as a code owner August 19, 2026 13:23
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 32257769945

Coverage decreased (-0.007%) to 75.104%

Details

  • Coverage decreased (-0.007%) from the base build.
  • Patch coverage: 23 of 23 lines across 7 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 3607
Covered Lines: 2709
Line Coverage: 75.1%
Coverage Strength: 54.21 hits per line

💛 - Coveralls

@umputun
umputun merged commit 4869f3a into master Aug 20, 2026
2 checks passed
@umputun
umputun deleted the go-fix branch August 20, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants