aspect-build / rules_lint

Run static analysis tools with Bazel
Apache License 2.0
62 stars 33 forks source link

[FR]: lint Go code #208

Open alexeagle opened 2 months ago

alexeagle commented 2 months ago

What is the current behavior?

With #207 we no longer have any Go linters.

Describe the feature

137 and #129 were bugs when golangci-lint was in this repo, those need to be solved for a roll-forward.

mrmeku commented 2 months ago

In prior projects, I've used the github action provided by golang ci lint itself which supports its own only report only new issues implementation via only-new-issues: true. I wonder if that strategy can be applied here. Let the linter have access to all source files but cull the reported errors to just those affected by a git diff.

alexeagle commented 2 months ago

Doesn't work with our design here that lints are just actions that visit the go_library graph and rely on Bazel's action caching (and remote execution). Having git information available to the linter would make it non-hermetic and not follow that design. But let's chat, maybe there's a middle path here I'm not seeing.

ewhauser commented 1 month ago

I think it is worth trying to run a nogo binary as rules_lint compatible linter as opposed to trying to coerce golangci-lint to work in a Bazel way. You can run all the same analyzers with nogo that you can run under golangci-lint.

This is the approach that gVisor takes: https://github.com/google/gvisor/blob/master/tools/nogo/defs.bzl

alexeagle commented 1 month ago

Ooh that example should be really helpful, thanks!