Vim-go: Errcheck flags for GoMetalinter

Created on 28 Jul 2017  路  3Comments  路  Source: fatih/vim-go

Behavior

This is a follow-up to #1244, which I found while trying to answer this question for myself.

I'd like to pass the --blank and --ignoretests flags to errcheck when using :GoMetalinter.

Steps to reproduce:

I can pass arguments to errcheck from the command line using this GoMetalinter command:

gometalinter --linter='errcheck:errcheck --blank --ignoretests {path}:PATH:LINE:MESSAGE' --disable-all --enable=errcheck .

I can also get this behavior to happen by directly setting g:go_metalinter_command, but this prevents me from having different autosave and manual linter lists for the metalinter. I'd love a feature that lets me define the a custom linter definition for GoMetalinter to be used when that linter is enabled, as I'm doing with the command-line above.

improvement

Most helpful comment

Yes. If I set g:go_metalinter_command, I lose the ability to have different metalinter settings for g:go_metalinter_autosave_enabled and :GoMetalinter.

I'd like to be able to set commands or add flags for individual linters - something like:

let g:go_metalinter_enabled = ['vet', 'errcheck --blank --lint', 'golint']
let g:go_metalinter_autosave_enabled = ['vet']

All 3 comments

If I understand you correctly you want to have the :GoMetalinter command to run gometalinter with different flags than the gometalinter command that's run when you have g:go_metalinter_autosave enabled?

Yes. If I set g:go_metalinter_command, I lose the ability to have different metalinter settings for g:go_metalinter_autosave_enabled and :GoMetalinter.

I'd like to be able to set commands or add flags for individual linters - something like:

let g:go_metalinter_enabled = ['vet', 'errcheck --blank --lint', 'golint']
let g:go_metalinter_autosave_enabled = ['vet']

You can accomplish this by using autocommands to change g:go_metalinter_enabled before the buffer is written and change it back after it's been written (you'll need to make sure that the autocommands are configured to run in the right order respective to vim-go's autocommands, though).

Something like autocmd BufWritePre <buffer> let g:go_metalinter_enabled = ['vet'] in $VIM/ftplugin/go.vim and autocmd BufWritePost <buffer> let g:go_metalinter_enabled = ['vet', 'errcheck --blank --lint', 'golint'] in $VIM/after/ftplugin/go.vim should work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Michael-F-Ellis picture Michael-F-Ellis  路  3Comments

johnzeng picture johnzeng  路  3Comments

smontazeran picture smontazeran  路  4Comments

korjavin picture korjavin  路  4Comments

cassiobotaro picture cassiobotaro  路  3Comments