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. 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* staticcheck *ale-go-staticcheck*

View file

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

View file

@ -2379,6 +2379,7 @@ documented in additional help files.
gometalinter..........................|ale-go-gometalinter| gometalinter..........................|ale-go-gometalinter|
gopls.................................|ale-go-gopls| gopls.................................|ale-go-gopls|
govet.................................|ale-go-govet| govet.................................|ale-go-govet|
revive................................|ale-go-revive|
staticcheck...........................|ale-go-staticcheck| staticcheck...........................|ale-go-staticcheck|
graphql.................................|ale-graphql-options| graphql.................................|ale-graphql-options|
eslint................................|ale-graphql-eslint| 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: * [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: * [gotype](https://godoc.org/golang.org/x/tools/cmd/gotype) :warning: :floppy_disk:
* [go vet](https://golang.org/cmd/vet/) :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: * [staticcheck](https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck) :warning: :floppy_disk:
* GraphQL * GraphQL
* [eslint](http://eslint.org/) * [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'