Make the executable for gometalinter configurable

This commit is contained in:
w0rp 2017-07-07 00:10:30 +01:00
parent 854066e849
commit 8315c0e337
3 changed files with 82 additions and 15 deletions

View File

@ -1,16 +1,22 @@
" Author: Ben Reedy <https://github.com/breed808>
" Description: Adds support for the gometalinter suite for Go files
if !exists('g:ale_go_gometalinter_options')
let g:ale_go_gometalinter_options = ''
endif
call ale#Set('go_gometalinter_options', '')
call ale#Set('go_gometalinter_executable', 'gometalinter')
function! ale_linters#go#gometalinter#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'go_gometalinter_executable')
endfunction
function! ale_linters#go#gometalinter#GetCommand(buffer) abort
let l:executable = ale_linters#go#gometalinter#GetExecutable(a:buffer)
let l:filename = expand('#' . a:buffer . ':p')
let l:options = ale#Var(a:buffer, 'go_gometalinter_options')
return 'gometalinter --include=''^' . l:filename . '.*$'' '
\ . ale#Var(a:buffer, 'go_gometalinter_options')
\ . ' ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h'))
return ale#Escape(l:executable)
\ . ' --include=''^' . l:filename . '.*$'''
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' ' . ale#Escape(fnamemodify(l:filename, ':h'))
endfunction
function! ale_linters#go#gometalinter#GetMatches(lines) abort
@ -36,7 +42,7 @@ endfunction
call ale#linter#Define('go', {
\ 'name': 'gometalinter',
\ 'executable': 'gometalinter',
\ 'executable_callback': 'ale_linters#go#gometalinter#GetExecutable',
\ 'command_callback': 'ale_linters#go#gometalinter#GetCommand',
\ 'callback': 'ale_linters#go#gometalinter#Handler',
\ 'lint_file': 1,

View File

@ -1,5 +1,5 @@
===============================================================================
ALE Go Integration *ale-go-options*
ALE Go Integration *ale-go-options*
-------------------------------------------------------------------------------
@ -21,20 +21,28 @@ while ensuring it doesn't run any linters known to be slow or resource
intensive.
-------------------------------------------------------------------------------
gometalinter *ale-go-gometalinter*
gometalinter *ale-go-gometalinter*
g:ale_go_gometalinter_options *g:ale_go_gometalinter_options*
*b:ale_go_gometalinter_options*
g:ale_go_gometalinter_executable *g:ale_go_gometalinter_executable*
*b:ale_go_gometalinter_executable*
Type: |String|
Default: `'gometalinter'`
The executable that will be run for gometalinter.
g:ale_go_gometalinter_options *g:ale_go_gometalinter_options*
*b:ale_go_gometalinter_options*
Type: |String|
Default: `''`
This variable can be changed to alter the command-line arguments to the
gometalinter invocation.
Since `gometalinter` runs a number of linters that can consume a lot of
resources it's recommended to set this option to a value of `--fast` if you
use `gometalinter` as one of the linters in |g:ale_linters|. This disables a
number of linters known to be slow or consume a lot of resources.
Since `gometalinter` runs a number of linters that can consume a lot of
resources it's recommended to set this option to a value of `--fast` if you
use `gometalinter` as one of the linters in |g:ale_linters|. This disables a
number of linters known to be slow or consume a lot of resources.
-------------------------------------------------------------------------------

View File

@ -0,0 +1,53 @@
Before:
Save b:ale_go_gometalinter_executable
Save b:ale_go_gometalinter_options
let b:ale_go_gometalinter_executable = 'gometalinter'
let b:ale_go_gometalinter_options = ''
runtime ale_linters/go/gometalinter.vim
silent! cd /testplugin/test/command_callback
let g:dir = getcwd()
call ale#test#SetFilename('test.go')
After:
Restore
silent execute 'cd ' . fnameescape(g:dir)
unlet! g:dir
call ale#linter#Reset()
Execute(The gometalinter callback should return the right defaults):
AssertEqual
\ 'gometalinter',
\ ale_linters#go#gometalinter#GetExecutable(bufnr(''))
AssertEqual
\ ale#Escape('gometalinter')
\ . ' --include=''^' . expand('%:p') . '.*$'''
\ . ' ' . ale#Escape(getcwd()),
\ ale_linters#go#gometalinter#GetCommand(bufnr(''))
Execute(The gometalinter callback should use a configured executable):
let b:ale_go_gometalinter_executable = 'something else'
AssertEqual
\ 'something else',
\ ale_linters#go#gometalinter#GetExecutable(bufnr(''))
AssertEqual
\ ale#Escape('something else')
\ . ' --include=''^' . expand('%:p') . '.*$'''
\ . ' ' . ale#Escape(getcwd()),
\ ale_linters#go#gometalinter#GetCommand(bufnr(''))
Execute(The gometalinter callback should use configured options):
let b:ale_go_gometalinter_options = '--foobar'
AssertEqual
\ ale#Escape('gometalinter')
\ . ' --include=''^' . expand('%:p') . '.*$'''
\ . ' --foobar'
\ . ' ' . ale#Escape(getcwd()),
\ ale_linters#go#gometalinter#GetCommand(bufnr(''))