summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/go/gometalinter.vim20
-rw-r--r--doc/ale-go.txt24
-rw-r--r--test/command_callback/test_gometalinter_command_callback.vader53
3 files changed, 82 insertions, 15 deletions
diff --git a/ale_linters/go/gometalinter.vim b/ale_linters/go/gometalinter.vim
index 671b77cf..db7f7c11 100644
--- a/ale_linters/go/gometalinter.vim
+++ b/ale_linters/go/gometalinter.vim
@@ -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,
diff --git a/doc/ale-go.txt b/doc/ale-go.txt
index e8c8914e..fa743570 100644
--- a/doc/ale-go.txt
+++ b/doc/ale-go.txt
@@ -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.
-------------------------------------------------------------------------------
diff --git a/test/command_callback/test_gometalinter_command_callback.vader b/test/command_callback/test_gometalinter_command_callback.vader
new file mode 100644
index 00000000..dcaf03b0
--- /dev/null
+++ b/test/command_callback/test_gometalinter_command_callback.vader
@@ -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(''))