BurntSushi / go-sumtype

A simple utility for running exhaustiveness checks on Go "sum types."

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Package as library so gometalinter can use it

atombender opened this issue · comments

I've started using this tool, but it's annoying that I can't get inline errors in my editor. Integrating it into gometalinter would be an obvious step, I think. For that to happen, I suspect some changes will be needed to make the API publicly importable.

I'd be open to that. I'm not sure when I'd get around to it though.

You know, I thought gometalinter actually used linters as libraries. But I now see that it merely invokes them as command-line tools. (Probably not very efficient — I bet most of them use the standard Go libs to parse the AST and do something with it — so that surprised me.) So it should be possible and fairly trivial to add support into gometalinter without any additional modifications.

@atombender That's interesting. go-sumtype can take quite a bit of time to run on medium sized projects, and a lot of that time is spent loading the entire source tree into an AST and type checking it, including vendor directories. (It would be possible to do this more efficiently I think, and I tried, but I got to a point where I'd have to end up re-implementing GOPATH.) But if all the linters do this and they are independent of each other, then yeah, I can see that being a drag.

Indeed, gometalinter turns out to be very slow if you enable too many linters, precisely because they're all doing a lot of work. It runs them in parallel, I believe. It even has a deadline system to prevent running amok.

I'm sure it would be possible to get a big performance boost from turning linters into libraries which can then ask the caller for an AST. The AST can then be cached across lint runs. Last I checked, gometalinter wasn't a server, but it probably should be, like gocode.

Hi, I realise that this thread is over 4 years old but I just stumbled across it. I think this is a useful tool and would like to be able to integrate it with https://github.com/golangci/golangci-lint.

As far as I can tell it looks like the easiest way would be to use the golang.org/x/tools/go/analysis package and moving the logic into a subdirectory so that the Analyzer can be imported.

I have put together a POC that does this and was wondering if it is worth cleaning it up & finishing it to submit a PR?

@ifross89 Yeah! I think that sounds great. Thank you. :-)