summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorElias Martinez Cohen <eliasc@nvidia.com>2019-04-10 22:25:06 -0400
committerElias Martinez Cohen <eliasc@nvidia.com>2019-07-01 11:04:33 -0400
commit49db8210f68637a2af14b21940f3cbbaf7361047 (patch)
tree366a5e30c22c40b2cf508b2edca6bf8ac25e6072 /ale_linters
parent89f7292138087e1410b2430ae6d359d42e7fe31f (diff)
downloadale-49db8210f68637a2af14b21940f3cbbaf7361047.zip
Support $GO111MODULE with Go tooling
Allows the user to override $GO111MODULE environment variable through ale options. This gives control over the default behavior of Go module resolution. Golang documentation: https://github.com/golang/go/wiki/Modules#how-to-use-modules Add `ale#Go#EnvString()` function to make it easy to add similar Go environment variables in the future. Use the new `EnvString` function in all available Go tools callbacks & update tests Also add test of linter command callback for `gofmt`
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/go/bingo.vim6
-rw-r--r--ale_linters/go/gobuild.vim1
-rw-r--r--ale_linters/go/gofmt.vim8
-rw-r--r--ale_linters/go/golangci_lint.vim3
-rw-r--r--ale_linters/go/golint.vim2
-rw-r--r--ale_linters/go/gometalinter.vim2
-rw-r--r--ale_linters/go/gopls.vim8
-rw-r--r--ale_linters/go/gosimple.vim3
-rw-r--r--ale_linters/go/gotype.vim3
-rw-r--r--ale_linters/go/govet.vim1
-rw-r--r--ale_linters/go/langserver.vim3
-rw-r--r--ale_linters/go/staticcheck.vim5
12 files changed, 34 insertions, 11 deletions
diff --git a/ale_linters/go/bingo.vim b/ale_linters/go/bingo.vim
index e446bdcc..1e43f8e4 100644
--- a/ale_linters/go/bingo.vim
+++ b/ale_linters/go/bingo.vim
@@ -5,11 +5,13 @@ call ale#Set('go_bingo_executable', 'bingo')
call ale#Set('go_bingo_options', '--mode stdio')
function! ale_linters#go#bingo#GetCommand(buffer) abort
- return '%e' . ale#Pad(ale#Var(a:buffer, 'go_bingo_options'))
+ return ale#go#EnvString(a:buffer) . '%e' . ale#Pad(ale#Var(a:buffer, 'go_bingo_options'))
endfunction
function! ale_linters#go#bingo#FindProjectRoot(buffer) abort
- let l:project_root = ale#path#FindNearestFile(a:buffer, 'go.mod')
+ let l:go_modules_off = ale#Var(a:buffer, 'go_go111module') is# 'off'
+ let l:project_root = l:go_modules_off ?
+ \ '' : ale#path#FindNearestFile(a:buffer, 'go.mod')
let l:mods = ':h'
if empty(l:project_root)
diff --git a/ale_linters/go/gobuild.vim b/ale_linters/go/gobuild.vim
index 374ded35..1dfb6daa 100644
--- a/ale_linters/go/gobuild.vim
+++ b/ale_linters/go/gobuild.vim
@@ -11,6 +11,7 @@ function! ale_linters#go#gobuild#GetCommand(buffer) abort
" Run go test in local directory with relative path
return ale#path#BufferCdString(a:buffer)
+ \ . ale#go#EnvString(a:buffer)
\ . ale#Var(a:buffer, 'go_go_executable') . ' test'
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' -c -o /dev/null ./'
diff --git a/ale_linters/go/gofmt.vim b/ale_linters/go/gofmt.vim
index 337deef8..a233b422 100644
--- a/ale_linters/go/gofmt.vim
+++ b/ale_linters/go/gofmt.vim
@@ -1,10 +1,16 @@
" Author: neersighted <bjorn@neersighted.com>
" Description: gofmt for Go files
+function! ale_linters#go#gofmt#GetCommand(buffer) abort
+ return ale#go#EnvString(a:buffer)
+ \ . '%e -e %t'
+endfunction
+
+
call ale#linter#Define('go', {
\ 'name': 'gofmt',
\ 'output_stream': 'stderr',
\ 'executable': 'gofmt',
-\ 'command': 'gofmt -e %t',
+\ 'command': function('ale_linters#go#gofmt#GetCommand'),
\ 'callback': 'ale#handlers#unix#HandleAsError',
\})
diff --git a/ale_linters/go/golangci_lint.vim b/ale_linters/go/golangci_lint.vim
index 357f7949..dd0e975a 100644
--- a/ale_linters/go/golangci_lint.vim
+++ b/ale_linters/go/golangci_lint.vim
@@ -10,13 +10,16 @@ function! ale_linters#go#golangci_lint#GetCommand(buffer) abort
let l:options = ale#Var(a:buffer, 'go_golangci_lint_options')
let l:lint_package = ale#Var(a:buffer, 'go_golangci_lint_package')
+
if l:lint_package
return ale#path#BufferCdString(a:buffer)
+ \ . ale#go#EnvString(a:buffer)
\ . '%e run '
\ . l:options
endif
return ale#path#BufferCdString(a:buffer)
+ \ . ale#go#EnvString(a:buffer)
\ . '%e run '
\ . ale#Escape(l:filename)
\ . ' ' . l:options
diff --git a/ale_linters/go/golint.vim b/ale_linters/go/golint.vim
index 765e1477..79bfaeb5 100644
--- a/ale_linters/go/golint.vim
+++ b/ale_linters/go/golint.vim
@@ -7,7 +7,7 @@ call ale#Set('go_golint_options', '')
function! ale_linters#go#golint#GetCommand(buffer) abort
let l:options = ale#Var(a:buffer, 'go_golint_options')
- return '%e'
+ return ale#go#EnvString(a:buffer) . '%e'
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' %t'
endfunction
diff --git a/ale_linters/go/gometalinter.vim b/ale_linters/go/gometalinter.vim
index 19d70a81..eed9550a 100644
--- a/ale_linters/go/gometalinter.vim
+++ b/ale_linters/go/gometalinter.vim
@@ -14,11 +14,13 @@ function! ale_linters#go#gometalinter#GetCommand(buffer) abort
" be calculated to absolute paths in the Handler
if l:lint_package
return ale#path#BufferCdString(a:buffer)
+ \ . ale#go#EnvString(a:buffer)
\ . '%e'
\ . (!empty(l:options) ? ' ' . l:options : '') . ' .'
endif
return ale#path#BufferCdString(a:buffer)
+ \ . ale#go#EnvString(a:buffer)
\ . '%e'
\ . ' --include=' . ale#Escape(ale#util#EscapePCRE(l:filename))
\ . (!empty(l:options) ? ' ' . l:options : '') . ' .'
diff --git a/ale_linters/go/gopls.vim b/ale_linters/go/gopls.vim
index c411dc2b..dcff5ec7 100644
--- a/ale_linters/go/gopls.vim
+++ b/ale_linters/go/gopls.vim
@@ -6,11 +6,15 @@ call ale#Set('go_gopls_executable', 'gopls')
call ale#Set('go_gopls_options', '--mode stdio')
function! ale_linters#go#gopls#GetCommand(buffer) abort
- return '%e' . ale#Pad(ale#Var(a:buffer, 'go_gopls_options'))
+ return ale#go#EnvString(a:buffer)
+ \ . '%e'
+ \ . ale#Pad(ale#Var(a:buffer, 'go_gopls_options'))
endfunction
function! ale_linters#go#gopls#FindProjectRoot(buffer) abort
- let l:project_root = ale#path#FindNearestFile(a:buffer, 'go.mod')
+ let l:go_modules_off = ale#Var(a:buffer, 'go_go111module') is# 'off'
+ let l:project_root = l:go_modules_off ?
+ \ '' : ale#path#FindNearestFile(a:buffer, 'go.mod')
let l:mods = ':h'
if empty(l:project_root)
diff --git a/ale_linters/go/gosimple.vim b/ale_linters/go/gosimple.vim
index 281a0e53..ad52c621 100644
--- a/ale_linters/go/gosimple.vim
+++ b/ale_linters/go/gosimple.vim
@@ -2,7 +2,8 @@
" Description: gosimple for Go files
function! ale_linters#go#gosimple#GetCommand(buffer) abort
- return ale#path#BufferCdString(a:buffer) . ' gosimple .'
+ return ale#path#BufferCdString(a:buffer) . ' '
+ \ . ale#go#EnvString(a:buffer) . 'gosimple .'
endfunction
call ale#linter#Define('go', {
diff --git a/ale_linters/go/gotype.vim b/ale_linters/go/gotype.vim
index d5d563aa..6a5149ca 100644
--- a/ale_linters/go/gotype.vim
+++ b/ale_linters/go/gotype.vim
@@ -6,7 +6,8 @@ function! ale_linters#go#gotype#GetCommand(buffer) abort
return ''
endif
- return ale#path#BufferCdString(a:buffer) . ' gotype -e .'
+ return ale#path#BufferCdString(a:buffer) . ' '
+ \ . ale#go#EnvString(a:buffer) . 'gotype -e .'
endfunction
call ale#linter#Define('go', {
diff --git a/ale_linters/go/govet.vim b/ale_linters/go/govet.vim
index bb81d5d0..dddafe17 100644
--- a/ale_linters/go/govet.vim
+++ b/ale_linters/go/govet.vim
@@ -11,6 +11,7 @@ function! ale_linters#go#govet#GetCommand(buffer) abort
let l:options = ale#Var(a:buffer, 'go_govet_options')
return ale#path#BufferCdString(a:buffer) . ' '
+ \ . ale#go#EnvString(a:buffer)
\ . ale#Var(a:buffer, 'go_go_executable') . ' vet '
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' .'
diff --git a/ale_linters/go/langserver.vim b/ale_linters/go/langserver.vim
index 776186c7..7130db40 100644
--- a/ale_linters/go/langserver.vim
+++ b/ale_linters/go/langserver.vim
@@ -15,8 +15,9 @@ function! ale_linters#go#langserver#GetCommand(buffer) abort
endif
let l:options = uniq(sort(l:options))
+ let l:env = ale#go#EnvString(a:buffer)
- return join(extend(l:executable, l:options), ' ')
+ return l:env . join(extend(l:executable, l:options), ' ')
endfunction
call ale#linter#Define('go', {
diff --git a/ale_linters/go/staticcheck.vim b/ale_linters/go/staticcheck.vim
index 26fe0193..ed40c6c2 100644
--- a/ale_linters/go/staticcheck.vim
+++ b/ale_linters/go/staticcheck.vim
@@ -8,17 +8,18 @@ function! ale_linters#go#staticcheck#GetCommand(buffer) abort
let l:filename = expand('#' . a:buffer . ':t')
let l:options = ale#Var(a:buffer, 'go_staticcheck_options')
let l:lint_package = ale#Var(a:buffer, 'go_staticcheck_lint_package')
+ let l:env = ale#go#EnvString(a:buffer)
" BufferCdString is used so that we can be sure the paths output from
" staticcheck can be calculated to absolute paths in the Handler
if l:lint_package
return ale#path#BufferCdString(a:buffer)
- \ . 'staticcheck'
+ \ . l:env . 'staticcheck'
\ . (!empty(l:options) ? ' ' . l:options : '') . ' .'
endif
return ale#path#BufferCdString(a:buffer)
- \ . 'staticcheck'
+ \ . l:env . 'staticcheck'
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' ' . ale#Escape(l:filename)
endfunction