Skip to content

Commit

Permalink
Support revive for go files (#2933)
Browse files Browse the repository at this point in the history
Signed-off-by: Penghui Liao <[email protected]>
  • Loading branch information
paco0x authored May 22, 2020
1 parent 7ff87a9 commit 7265ceb
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ale_linters/go/revive.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
" Author: Penghui Liao <[email protected]>
" 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',
\})
19 changes: 19 additions & 0 deletions doc/ale-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Notes:
* `gosimple`!!
* `gotype`!!
* `go vet`!!
* `revive`!!
* `staticcheck`!!
* GraphQL
* `eslint`
Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
30 changes: 30 additions & 0 deletions test/command_callback/test_revive_command_callbacks.vader
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 7265ceb

Please sign in to comment.