fatih/vim-go

Request: golangci-lint support with go-vim

stefanos82 opened this issue ยท 18 comments

The project description sounds very nice!

Linters Runner for Go. 5x faster than gometalinter.

https://github.com/golangci/golangci-lint

when?

fatih commented

I'm not sure how maintainable this project is. It vendors and modifies all current linters: https://github.com/golangci/golangci-lint#internals It just doesn't vendor them, it even changes them and modifies them to a point that they are not the same anymore. How can I be sure that vet is the same original vet when I call golangci-lint? gometalinter might be slow, but you can be assured it's using the original tool and source, instead of a modified one.

I'm not saying it's the wrong way or etc.. I know they have a product offering and trying to earn money with this project, but we have to keep vim-go in a maintainable state. The last thing we want is to fix bugs that might be caused by third-party linter forks.

I'm not going to close this for now, happy to read other people thoughts on this.

@fatih we're upstreaming changes and it will take some time to prepare changes, review and merge them by linters authors.

The problem with vet is that it lives in go source code: it's too big repo to vendor it. First we decided to make subtree of go source code with only vet code, but even this repo cloning was super-slow because of long git history. Therefore we've just made a copy of vet source code and you can't be sure that it's the same original vet. It has pros (users of old go version can use newer vet) and cons (not official way, less guarantees).

Maybe something has changed since I've tried to auto-run gometalinter on file save, but at that time it was incredible slow - wait for 1-3 seconds on each save is not an option. So, I give up and run it manually in console before pushing changes and within CI. If golangci-lint will be fast enough to make it possible to auto-run it on save without noticeable slowdown of vim - I think it's worth to support! Even if it uses modified linters and even if they behave a bit differently - it's just a linters, if they catch most of issues then it's better than nothing.

At a glance it looks like it may be that fast, but only when called with --fast flag, otherwise it takes about 3 seconds - too slow to auto-run on save.

Hi!
I am the author of golangci-lint.
I just want to note that this issue is the most liked issue in your repo and golangci-lint is already integrated with VS Code, Sublime, Goland, GNU Emacs.

Thanks for the updates. Especially given Alec Thomas's comments, it seems like replacing gometalinter in vim-go is warranted. After golsp intergration is merged (the focus of my current efforts for vim-go), I can get started on replacing gometalinter if no one else submits the PR before then.

For anyone following along and looking for this issue to be resolved with formal support in vim-go, you may be able to start using golangci-lint as-is by leveraging g:go_metalinter_command in the interim.

stmuk commented

or add the following to your .vimrc

command GOLINT :cexpr system('golangci-lint run')

and use :GOINT (the first character has to capitalised but not those following!

@bhcleek I'm trying that right now but I can't seem to make it so I can jump to the lines from the output. Did you manage to make that work ?

Is there more documentation for the g:go_metalinter_command setting?

Is there more documentation for the g:go_metalinter_command setting?

vim-go/doc/vim-go.txt

Lines 1499 to 1506 in 66d06f3

*'g:go_metalinter_command'*
Overrides the command to be executed when |:GoMetaLinter| is called. This is
an advanced settings and is for users who want to have a complete control
over how `gometalinter` should be executed. By default it's empty.
>
let g:go_metalinter_command = ""
<

@vrischmann I haven't tried it. If golangci-lint's output is formatted differently than gometalinter's, then it's unlikely to work.

gometalinter mostly works, so this issue is a lower priority for me than getting the gopls intergration going. Once I get done with that, I'll put some attention to moving from gometalinter to golangci-lint.

I started a WIP here, but some of the details of what we want the default config to look like still need to get hashed out #2182

jonaz commented

https://github.com/alecthomas/gometalinter
gometalinter is DEPRECATED and the project will be archived on 2019-04-07.

Would be nice to have golangci-lint as a replacement since thats they are recomending.

While waiting for golangci-lint, I would like to share my current workaround using ~/.vimrc. Let me know what else I can help to accelerate the effort.

" go programming language
autocmd BufWritePost *.go !gofmt -w -s %:p
autocmd BufWritePost *.go !clear && golangci-lint run --color never --enable-all %:p:h

Tested on Debian Stretch.

golangci-lint support was added in #2182