Support revive for go files (#2933)

Signed-off-by: Penghui Liao <liaoishere@gmail.com>
This commit is contained in:
Paco 2020-05-22 19:09:14 +08:00 committed by GitHub
parent 7ff87a942b
commit 7265ceb6d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 0 deletions

21
ale_linters/go/revive.vim Normal file
View File

@ -0,0 +1,21 @@
" Author: Penghui Liao <liaoishere@gmail.com>
" Description: Adds support for revive
call ale#Set('go_revive_executable', 'revive')
call ale#Set('go_revive_options', '')
function! ale_linters#go#revive#GetCommand(buffer) abort
let l:options = ale#Var(a:buffer, 'go_revive_options')
return ale#go#EnvString(a:buffer) . '%e'
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' %t'
endfunction
call ale#linter#Define('go', {
\ 'name': 'revive',
\ 'output_stream': 'both',
\ 'executable': {b -> ale#Var(b, 'go_revive_executable')},
\ 'command': function('ale_linters#go#revive#GetCommand'),
\ 'callback': 'ale#handlers#unix#HandleAsWarning',
\})

View File

@ -219,6 +219,25 @@ g:ale_go_govet_options *g:ale_go_govet_options*
This variable can be set to pass additional options to the go vet linter.
===============================================================================
revive *ale-go-revive*
g:ale_go_revive_executable *g:ale_go_revive_executable*
*b:ale_go_revive_executable*
Type: |String|
Default: `'revive'`
This variable can be set to change the revive executable path.
g:ale_go_revive_options *g:ale_go_revive_options*
*b:ale_go_revive_options*
Type: |String|
Default: `''`
This variable can be set to pass additional options to the revive
===============================================================================
staticcheck *ale-go-staticcheck*

View File

@ -164,6 +164,7 @@ Notes:
* `gosimple`!!
* `gotype`!!
* `go vet`!!
* `revive`!!
* `staticcheck`!!
* GraphQL
* `eslint`

View File

@ -2379,6 +2379,7 @@ documented in additional help files.
gometalinter..........................|ale-go-gometalinter|
gopls.................................|ale-go-gopls|
govet.................................|ale-go-govet|
revive................................|ale-go-revive|
staticcheck...........................|ale-go-staticcheck|
graphql.................................|ale-graphql-options|
eslint................................|ale-graphql-eslint|

View File

@ -173,6 +173,7 @@ formatting.
* [gosimple](https://github.com/dominikh/go-tools/tree/master/cmd/gosimple) :warning: :floppy_disk:
* [gotype](https://godoc.org/golang.org/x/tools/cmd/gotype) :warning: :floppy_disk:
* [go vet](https://golang.org/cmd/vet/) :floppy_disk:
* [revive](https://github.com/mgechev/revive) :warning: :floppy_disk:
* [staticcheck](https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck) :warning: :floppy_disk:
* GraphQL
* [eslint](http://eslint.org/)

View File

@ -0,0 +1,30 @@
Before:
Save g:ale_go_go111module
call ale#assert#SetUpLinterTest('go', 'revive')
After:
Restore
unlet! b:ale_go_go111module
call ale#assert#TearDownLinterTest()
Execute(The default revive command should be correct):
AssertLinter 'revive', ale#Escape('revive') . ' %t'
Execute(The revive executable should be configurable):
let b:ale_go_revive_executable = 'foobar'
AssertLinter 'foobar', ale#Escape('foobar') . ' %t'
Execute(The revive options should be configurable):
let b:ale_go_revive_options = '--foo'
AssertLinter 'revive', ale#Escape('revive') . ' --foo %t'
Execute(The revive command should support Go environment variables):
let b:ale_go_go111module = 'on'
AssertLinter 'revive',
\ ale#Env('GO111MODULE', 'on') . ale#Escape('revive') . ' %t'