feat(marshal-receiver): add marshal-receiver rule#1707
Open
roidelapluie wants to merge 1 commit intomgechev:masterfrom
Open
feat(marshal-receiver): add marshal-receiver rule#1707roidelapluie wants to merge 1 commit intomgechev:masterfrom
roidelapluie wants to merge 1 commit intomgechev:masterfrom
Conversation
Add a new rule that enforces correct receiver types for Marshal/Unmarshal methods: MarshalJSON/MarshalYAML should use value receivers, while UnmarshalJSON/UnmarshalYAML should use pointer receivers. Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new marshal-receiver lint rule to detect incorrect receiver types for common JSON/YAML marshal/unmarshal methods, addressing subtle serialization bugs described in #1706.
Changes:
- Implement
MarshalReceiverRuleto enforce value receivers forMarshalJSON/MarshalYAMLand pointer receivers forUnmarshalJSON/UnmarshalYAML. - Register the rule in the global rule set and document it in
RULES_DESCRIPTIONS.md. - Add fixture-based coverage and a dedicated rule test.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
rule/marshal_receiver.go |
Implements the new receiver-type enforcement rule for marshal/unmarshal methods. |
config/config.go |
Registers the new rule in the list of available rules. |
config/config_test.go |
Updates the expected total rule count to include the new rule. |
test/marshal_receiver_test.go |
Adds a unit test running the rule against a new fixture. |
testdata/marshal_receiver.go |
Adds good/bad examples with expected failure messages for the new rule. |
RULES_DESCRIPTIONS.md |
Documents the new marshal-receiver rule and adds it to the rule index. |
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.
Add a new rule that enforces correct receiver types for Marshal/Unmarshal methods: MarshalJSON/MarshalYAML should use value receivers, while UnmarshalJSON/UnmarshalYAML should use pointer receivers.
see #1706