Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional metalinter options #631

Merged
merged 1 commit into from
Nov 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions autoload/go/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ if !exists("g:go_metalinter_command")
let g:go_metalinter_command = ""
endif

if !exists("g:go_metalinter_autosave_enabled")
let g:go_metalinter_autosave_enabled = ['vet', 'golint']
endif

if !exists("g:go_metalinter_enabled")
let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck']
endif
Expand All @@ -18,32 +22,35 @@ if !exists("g:go_errcheck_bin")
let g:go_errcheck_bin = "errcheck"
endif

function! go#lint#Gometa(...) abort
function! go#lint#Gometa(autosave, ...) abort
if a:0 == 0
let goargs = expand('%:p:h')
else
let goargs = go#util#Shelljoin(a:000)
endif

let meta_command = "gometalinter --disable-all"
if empty(g:go_metalinter_command)
if a:autosave || empty(g:go_metalinter_command)
let bin_path = go#path#CheckBinPath("gometalinter")
if empty(bin_path)
return
endif

if empty(g:go_metalinter_enabled)
echohl Error | echomsg "vim-go: please enable linters with the setting g:go_metalinter_enabled" | echohl None
return
if a:autosave
" include only messages for the active buffer
let meta_command .= " --include='^" . expand('%:p') . ".*$'"
endif

for linter in g:go_metalinter_enabled
" linters
let linters = a:autosave ? g:go_metalinter_autosave_enabled : g:go_metalinter_enabled
for linter in linters
let meta_command .= " --enable=".linter
endfor

" deadline
let meta_command .= " --deadline=" . g:go_metalinter_deadline

" path
let meta_command .= " " . goargs
else
" the user wants something else, let us use it.
Expand Down Expand Up @@ -73,7 +80,10 @@ function! go#lint#Gometa(...) abort

let errors = go#list#Get()
call go#list#Window(len(errors))
call go#list#JumpToFirst()

if !a:autosave
call go#list#JumpToFirst()
endif
endif
endfunction

Expand Down
13 changes: 13 additions & 0 deletions doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,20 @@ Adds custom text objects. By default it's enabled. >

let g:go_textobj_enabled = 1
<
*'g:go_metalinter_autosave'*

Use this option to auto |:GoMetaLinter| on save. Only linter messages for
the active buffer will be shown. By default it's disabled >

let g:go_metalinter_autosave = 0
<
*'g:go_metalinter_autosave_enabled'*

Specifies the enabled linters for auto |GoMetaLinter| on save. By
default it's using `vet` and `golint`
>
let g:go_metalinter_autosave_enabled = ['vet', 'golint']
<
*'g:go_metalinter_enabled'*

Specifies the currently enabled linters for the |GoMetaLinter| command. By
Expand Down
2 changes: 1 addition & 1 deletion ftplugin/go/commands.vim
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ command! -nargs=1 -bang -complete=customlist,go#package#Complete GoImport call g
command! -nargs=* -bang -complete=customlist,go#package#Complete GoImportAs call go#import#SwitchImport(1, <f-args>, '<bang>')

" -- linters
command! -nargs=* GoMetaLinter call go#lint#Gometa(<f-args>)
command! -nargs=* GoMetaLinter call go#lint#Gometa(0, <f-args>)
command! -nargs=* GoLint call go#lint#Golint(<f-args>)
command! -nargs=* -bang GoVet call go#lint#Vet(<bang>0, <f-args>)
command! -nargs=* -complete=customlist,go#package#Complete GoErrCheck call go#lint#Errcheck(<f-args>)
Expand Down
2 changes: 1 addition & 1 deletion ftplugin/go/mappings.vim
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ nnoremap <silent> <Plug>(go-doc-vertical) :<C-u>call go#doc#Open("vnew", "vsplit
nnoremap <silent> <Plug>(go-doc-split) :<C-u>call go#doc#Open("new", "split")<CR>
nnoremap <silent> <Plug>(go-doc-browser) :<C-u>call go#doc#OpenBrowser()<CR>

nnoremap <silent> <Plug>(go-metalinter) :<C-u>call go#lint#Gometa('')<CR>
nnoremap <silent> <Plug>(go-metalinter) :<C-u>call go#lint#Gometa(0)<CR>
nnoremap <silent> <Plug>(go-vet) :<C-u>call go#lint#Vet(!g:go_jump_to_error)<CR>


5 changes: 5 additions & 0 deletions plugin/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ augroup vim-go
autocmd BufWritePre *.go call go#fmt#Format(-1)
endif

" run gometalinter on save
if get(g:, "go_metalinter_autosave", 0)
autocmd BufWritePost *.go call go#lint#Gometa(1)
endif

augroup END


Expand Down