quasilyte / go-ruleguard

Define and run pattern-based custom linting rules.
https://go-ruleguard.github.io/
BSD 3-Clause "New" or "Revised" License
793 stars 42 forks source link

support to ignore cgo #130

Open jordanlewis opened 3 years ago

jordanlewis commented 3 years ago

Currently, ruleguard appears to exit early when encountering any cgo files. Here's an example against https://github.com/cockroachdb/cockroach:

[18:13]% ruleguard -c=0 -rules pkg/testutils/lint/ruleguard.rules.go ./pkg/sql/...   jordan@Jordans-MBP:~/go/src/github.com/cockroachdb/cockroach on master -> origin/master
/Users/jordan/go/src/github.com/cockroachdb/cockroach/vendor/github.com/knz/go-libedit/unix/editline_unix.go:42:8: could not import C (no metadata for C)
/Users/jordan/go/src/github.com/cockroachdb/cockroach/pkg/cli/start_jemalloc.go:49:8: could not import C (no metadata for C)
ruleguard: 2 errors during loading
[18:15:1]%

Would it be possible to ignore such errors?

Thanks for the great tool!

quasilyte commented 3 years ago

Interesting. I think it's a problem with a go/analysis there, because I don't load any pacakges on my own. The main function just calls a "framework" to do its thing. I wonder if this issue persists when ruleguard is used via golangci-lint?

The error you're seeing is probably comes from here: https://github.com/golang/tools/blob/d88ec18c69c70d818214bd2c98f3ce431ea4fd62/go/analysis/internal/checker/checker.go#L159

Would it be possible to ignore such errors?

That would require the main function rewrite as it uses "singlechecker" helper from the framework to do all the work. If golangci-lint does solve that problem, it would be easier to use ruleguard from that (as golangci-lint does include it).

There are so many unfortunate things that co go wrong when trying to "load" Go packages. :( Go modules made the picture slightly more problematic for the tool writers from one point of view (as the number of different options is now higher, not lower).