golangci-lint
golangci-lint copied to clipboard
Add golang.org/x/exp/apidiff as a linter
Your feature request related to a problem? Please describe.
When a developer makes a backwards-incompatible change to their API, it would be nice for a linter to warn them so they could make a conscious decision to do so.
Describe the solution you'd like.
Add golang.org/x/exp/apidiff as a disabled by default linter.
When enabled, golangci-lint should:
- Check if the version in go.mod is v1 or greater. If the module is v0, then backwards-incompatible changes are OK and the linter shouldn’t be run. Although it might make sense to add an option to
force-v0: true
. - Use GOPROXY to pull the same major version of the current module, which should be the latest public version. If this major version doesn’t exist, then this must be a major version bump, so backwards-incompatible changes are OK and the linter shouldn’t be run.
- Run apidiff against the public version of the module and warn
Describe alternatives you've considered.
There doesn’t seem to be a public alternative to apidiff, as of 2021-10-28.
Additional context.
Unfortunately, apidiff does not use the analysis framework.
It also isn’t aware of GOPROXY, so there probably needs to be a shim that reads the go.mod file and downloads the appropriate public version using golang.org/x/tools/go/packages. Thankfully, apidiff.Changes takes *types.Package arguments, so this shim shouldn’t be too bad.
I recommend apidiff be disabled by default since it is still experimental. That being said, Kubernetes is running it as part of their CI pipeline: https://github.com/kubernetes/utils/actions/runs/77631466/workflow.
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.