fix: use a value receiver for AppendText so generated enums pass recvcheck - #325
Merged
Merged
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (29)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe generator templates and generated enum outputs now use value receivers for ChangesAppendText receiver updates
Priority: ⬇️ Low Estimated code review effort: 1 (Trivial) | ~5 minutes Change: Bug fix 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
abice
approved these changes
Sep 21, 2026
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.
Every enum generated with
--marshaltrips golangci-lint'srecvchecklinter:so consumers end up adding
//nolint:recvcheckto every enum type declaration.Cause:
AppendTextis emitted on a pointer receiver (func (x *Foo) AppendText) while its siblingsString,IsValid,Ptr,MarshalText, andValueuse value receivers. recvcheck toleratesUnmarshalTexton a pointer receiver because that method is on the linter's built-in exclusion list (the standardUnmarshal*/GobDecodemethods, which have to mutate).AppendTextis not on that list, so it is the one method that makes the receiver set mixed.AppendTextonly reads the value (append(b, x.String()...)), so a value receiver is the correct choice and matchesMarshalText. BothFooand*Foostill satisfyencoding.TextAppender, since a pointer's method set includes the value-receiver methods.Change:
generator/enum.tmplandgenerator/enum_string.tmpl:func (x *{{.enum.Name}}) AppendTextbecomesfunc (x {{.enum.Name}}) AppendText.example/*_enum.go(make generate) and thegenerator/.snapshotsgolden files (UPDATE_SNAPSHOTS=true go test ./generator/...). Every changed line in those files is anAppendTextreceiver; nothing else moved.Enums generated with
--sqlor--flagstill carry pointer receivers onScan,Set,Get, andType. Those genuinely mutate the value and recvcheck does not exclude them, so this change does not silence the linter for those flag combinations; it only removes the one pointer receiver that had no reason to be one.Testing
Toolchain: go1.27.1, golangci-lint v2.13.2 (bundles recvcheck v0.3.0).
Unit tests on this branch (same commands as the Makefile
testtarget):Lint proof, in a scratch module containing only this file:
Generated with the unmodified v0.9.4 release:
Generated with
bin/go-enumbuilt from this branch:The only difference between the two generated files, apart from the version header, is the receiver:
Summary by CodeRabbit
Compatibility
Generated Code