Skip to content

feat: add SuggestedFixes for --fix support#19

Open
raeperd wants to merge 2 commits into
mainfrom
feat/suggested-fixes
Open

feat: add SuggestedFixes for --fix support#19
raeperd wants to merge 2 commits into
mainfrom
feat/suggested-fixes

Conversation

@raeperd
Copy link
Copy Markdown
Owner

@raeperd raeperd commented Apr 3, 2026

Why

golangci-lint supports --fix to auto-fix linter issues, but recvcheck only reports diagnostics without suggested fixes. Users have to manually change value receivers to pointer receivers.

What

Attach analysis.SuggestedFix with TextEdits that insert * before value receiver type names. When golangci-lint --fix is used, value receivers are automatically converted to pointer receivers.

Changes

  • Switch pass.Reportfpass.Report(analysis.Diagnostic{...}) with SuggestedFixes
  • Track value receiver *ast.Ident positions during AST walk
  • Switch tests to analysistest.RunWithSuggestedFixes with .go.golden files

Summary by CodeRabbit

  • New Features

    • Analyzer now provides automatic suggested fixes to convert non-pointer method receivers to pointer receivers, with text edits applied at the identifier positions.
  • Tests

    • Updated test harness to verify suggested fixes alongside diagnostics.
    • Added comprehensive test fixtures covering various serialization patterns.

raeperd added 2 commits April 4, 2026 00:07
Attach SuggestedFixes to diagnostics so golangci-lint --fix can
automatically convert value receivers to pointer receivers.
Switch tests to RunWithSuggestedFixes and add golden files.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 3, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3472fb74-f79e-4bec-a319-49299e954455

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/suggested-fixes

Comment @coderabbitai help to get the list of available commands and usage tips.

@raeperd raeperd self-assigned this Apr 3, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@analyzer.go`:
- Around line 105-112: The call pass.Pkg.Scope().Lookup(recv) can return nil and
calling .Pos() would panic; update the diagnostic creation in the block that
calls pass.Report so you first capture the result of
pass.Pkg.Scope().Lookup(recv) into a variable, check for nil, and use a safe
fallback position (for example token.NoPos or the position of the first related
method) when lookup is nil before passing Pos into analysis.Diagnostic; keep the
same Message and SuggestedFixes logic but supply the guarded position to avoid
nil dereference.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 833209dd-ae10-4d4a-9520-d22f79cd0e2e

📥 Commits

Reviewing files that changed from the base of the PR and between 8ade7fa and c0ef36c.

📒 Files selected for processing (9)
  • analyzer.go
  • analyzer_test.go
  • testdata/src/basic/rpc.go.golden
  • testdata/src/disablebuiltin/binary.go.golden
  • testdata/src/disablebuiltin/gob.go.golden
  • testdata/src/disablebuiltin/json.go.golden
  • testdata/src/disablebuiltin/text.go.golden
  • testdata/src/disablebuiltin/xml.go.golden
  • testdata/src/disablebuiltin/yaml.go.golden

Comment thread analyzer.go
@raeperd raeperd marked this pull request as ready for review April 3, 2026 16:14
@raeperd raeperd requested a review from ldez April 3, 2026 16:14
@ldez ldez added the enhancement New feature or request label Apr 13, 2026
@raeperd
Copy link
Copy Markdown
Owner Author

raeperd commented May 5, 2026

@ldez
could you take a look at this PR when you have time?

it should be the final enhancement for the next release, then I’ll open a PR to upgrade the linter version in golangci-lint.

@ldez
Copy link
Copy Markdown
Collaborator

ldez commented May 6, 2026

I can see 2 problems:

  • the report message is changed
  • the suggested fix only suggest to use a pointer

Before, the goal was to have consistent receiver types, after, the goal is to force the usage of pointer receiver when there is at least one pointer receiver.

@raeperd
Copy link
Copy Markdown
Owner Author

raeperd commented May 6, 2026

@ldez thanks for the review. I want to clarify two points.

About the report message: it didn’t change. Reportf formats the same diagnostic internally, and this PR keeps the exact same text:

the methods of %q use pointer receiver and non-pointer receiver.

The only added field is SuggestedFixes.

About the fix direction: yes, the suggested fix chooses pointer receivers.

I chose that direction because it is the safer automatic edit. Changing pointer receivers to value receivers can change mutation/copy/nil semantics, while changing value receivers to pointer receivers is the smaller local fix when this linter reports mixed receivers.

This also follows Go’s receiver guidance: “Don’t mix receiver types” and “Finally, when in doubt, use a pointer receiver”.
https://go.dev/wiki/CodeReviewComments#receiver-type

That said, I understand this can be too opinionated for --fix.

If you still think this should not be included, I’ll leave this PR open, release the current version first, and update recvcheck in golangci-lint. If this direction looks acceptable, I’ll include this PR in the next recvcheck release.

@ldez
Copy link
Copy Markdown
Collaborator

ldez commented May 6, 2026

I think this is too opinionated, I understand the goal, but I also know that using pointer receiver is not always the right solution.
Then this will create "false-positive fixes" and the users will complain about it.

A suggested fix is not a simple report message, it will change the code, the impact is important.

@ldez
Copy link
Copy Markdown
Collaborator

ldez commented May 6, 2026

I’ll open a PR to upgrade the linter version in golangci-lint.

FYI, we use dependabot to update the linters, you should not open a PR to update the linter.

@raeperd
Copy link
Copy Markdown
Owner Author

raeperd commented May 6, 2026

@ldez makes sense. I’ll keep this out of the next recvcheck release and leave it open for now.

Thanks for the golangci-lint note too — I’ll let Dependabot handle the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants