golangci-lint icon indicating copy to clipboard operation
golangci-lint copied to clipboard

feat: add go-refcheck linter

Open geraldywy opened this issue 2 years ago • 5 comments

Your feature request related to a problem? Please describe.

Add support for go-refcheck: https://github.com/geraldywy/go-refcheck

Does what copyfighter does, but go-refcheck is rewritten using go/analysis https://github.com/jmhodges/copyfighter

Describe the solution you'd like.

Integrate this linter as an option within golangci-lint

Describe alternatives you've considered.

Run it separately

Additional context.

No response

geraldywy avatar Aug 30 '21 15:08 geraldywy

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

boring-cyborg[bot] avatar Aug 30 '21 15:08 boring-cyborg[bot]

Hello,

I think that is already handled with gocritic https://github.com/go-critic/go-critic

Also, a project without any license is not usable.

ldez avatar Aug 30 '21 16:08 ldez

Hi,

Thanks for the reply. To my knowledge, not exactly. The closest match I could find was gocritic's hugeParam with a slight difference in that it reports passing of large structs by value in function params as opposed to func receivers which the linter is made for. Do correct me on this I am mistaken.

Also, I am the author of the proposed linter, I can add a license to it if need be.

geraldywy avatar Aug 30 '21 16:08 geraldywy

Maybe you can add a rule or improve a rule in go-critic because it feels very very close to some rules.

ldez avatar Aug 30 '21 16:08 ldez

go-critic pretty much support it.

image

butuzov avatar Aug 31 '21 03:08 butuzov

hugeParam checks any func declarations, methods too (and also supports some common exceptions like String()):

$ pwd
/tmp/go-refcheck/testdata/src/p

$ gocritic check -enable hugeParam [email protected]=32 p.go
./p.go:28:7: hugeParam: l is heavy (56 bytes); consider passing it by pointer
./p.go:32:7: hugeParam: l is heavy (56 bytes); consider passing it by pointer
./p.go:47:7: hugeParam: m is heavy (64 bytes); consider passing it by pointer
./p.go:61:7: hugeParam: n is heavy (32 bytes); consider passing it by pointer

If desired, you can improve their warning message for methods.

P.S. IMO, go-refcheck is not the best naming for such check. ref typically is about reference issues (loop closures, etc.)

Antonboom avatar Oct 01 '23 09:10 Antonboom