Skip to content

feat(marshal-receiver): add marshal-receiver rule#1707

Open
roidelapluie wants to merge 1 commit intomgechev:masterfrom
roidelapluie:marshal-receiver
Open

feat(marshal-receiver): add marshal-receiver rule#1707
roidelapluie wants to merge 1 commit intomgechev:masterfrom
roidelapluie:marshal-receiver

Conversation

@roidelapluie
Copy link
Copy Markdown

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

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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MarshalReceiverRule to enforce value receivers for MarshalJSON/MarshalYAML and pointer receivers for UnmarshalJSON/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.

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.

2 participants