Repository navigation
Apply go fix modernizations - #18
Merged
Merged
Conversation
Run `go fix ./...` for Go 1.27: ioutil.ReadAll -> io.ReadAll, integer range loops, min(), slices.Backward, and strings.Builder for string concatenation in a loop. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
go fix skips these because they pass new(T) or &T{} as the target.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
go fix skips these: IndexByte followed by slicing around the index, HasSuffix+TrimSuffix on bytes, and sort.SliceStable on a non-basic slice. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- slices.Delete replaces append(s[:i], s[i+1:]...) and zeroes the vacated slot so the removed field can be collected. - b.Loop replaces the b.N loops in the header benchmarks. - io.Discard replaces the last ioutil use. - charset errors wrap the underlying error with %w so errors.Is/As work. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The invalid-charset tests do not verify error unwrapping, leaving the intentional %w behavior unprotected against regression to %v.
1 open issue
What changed in this PR
Modernizes the message, mail, and textproto packages with current Go idioms and standard-library APIs. Charset lookup errors now expose their underlying cause; multipart EOF handling remains unchanged.
Changes:
- Replace legacy I/O helpers, loops, sorting, and slice deletion patterns.
- Use typed error matching and
strings.Builderfor comment parsing. - Wrap charset lookup errors and modernize benchmark loops.
| File | Description |
|---|---|
textproto/multipart.go |
Simplify read limits, replace discard helper, and document EOF handling. |
textproto/multipart_test.go |
Modernize I/O helpers and loop syntax. |
textproto/header.go |
Modernize sorting, byte splitting, reverse iteration, and deletion. |
textproto/bench_test.go |
Switch benchmarks to b.Loop(). |
mail/reader_test.go |
Replace ioutil.ReadAll with io.ReadAll. |
mail/header.go |
Build parsed comments with strings.Builder. |
entity_test.go |
Modernize I/O helpers and typed error assertions. |
encoding.go |
Update error matching, loops, and suffix splitting. |
encoding_test.go |
Replace the legacy read helper. |
charset/charset.go |
Preserve underlying charset lookup errors with %w. |
charset/charset_test.go |
Replace the legacy read helper. |
charset.go |
Use typed matching for unknown-charset errors. |
Review effort: Balanced
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.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.

Summary
Output of
go fix ./...on Go 1.27.3 (plus a stray blank line removed fromWriteHeader):ioutil.ReadAll->io.ReadAllfor i := 0; i < n; i++->for i := range nmin()slices.Backward+=in a loop ->strings.Builder(mail/header.go)Manual changes:
errors.Ascalls ->errors.AsType(by hand;go fixskips thenew(T)/&T{}target forms)bytes.IndexByte+ slicing ->bytes.Cut(AddRaw,trimAroundNewlines,parseHeaderFieldLine),HasSuffix+TrimSuffix->bytes.CutSuffix,sort.SliceStable->slices.SortStableFunc(all skipped bygo fix)append(s[:i], s[i+1:]...)->slices.Delete(also zeroes the vacated slot),b.Nloops ->b.Loop(), lastioutil.Discard->io.Discardcharset/charset.go:%v->%w, soerrors.Is/Assee the underlying error. This is the one behavior-visible change.multipart.go'sNextPart: %vis intentionally left as%v: wrapping would make a truncated body satisfyerrors.Is(err, io.EOF).Test plan
go test ./...go fix -diff ./...is empty afterwards🤖 Generated with Claude Code