Add support for bingo (#2165)

* Add support for https://github.com/saibing/bingo
* Add docs for ale-go-bingo
* Use go.mod when found
* Add test for bingo FindProjectRoot
* Simplify ale_linters#go#bingo#GetCommand
This commit is contained in:
Jerko Steiner 2019-01-05 19:12:55 +00:00 committed by w0rp
parent 4f3190daa8
commit 5bbe77101d
6 changed files with 101 additions and 3 deletions

View File

@ -133,7 +133,7 @@ formatting.
| FusionScript | [fusion-lint](https://github.com/RyanSquared/fusionscript) | | FusionScript | [fusion-lint](https://github.com/RyanSquared/fusionscript) |
| Git Commit Messages | [gitlint](https://github.com/jorisroovers/gitlint) | | Git Commit Messages | [gitlint](https://github.com/jorisroovers/gitlint) |
| GLSL | [glslang](https://github.com/KhronosGroup/glslang), [glslls](https://github.com/svenstaro/glsl-language-server) | | GLSL | [glslang](https://github.com/KhronosGroup/glslang), [glslls](https://github.com/svenstaro/glsl-language-server) |
| Go | [gofmt](https://golang.org/cmd/gofmt/), [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports), [go mod](https://golang.org/cmd/go/) !!, [go vet](https://golang.org/cmd/vet/) !!, [golint](https://godoc.org/github.com/golang/lint), [gotype](https://godoc.org/golang.org/x/tools/cmd/gotype) !!, [gometalinter](https://github.com/alecthomas/gometalinter) !!, [go build](https://golang.org/cmd/go/) !!, [gosimple](https://github.com/dominikh/go-tools/tree/master/cmd/gosimple) !!, [staticcheck](https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck) !!, [golangserver](https://github.com/sourcegraph/go-langserver), [golangci-lint](https://github.com/golangci/golangci-lint) !! | | Go | [gofmt](https://golang.org/cmd/gofmt/), [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports), [go mod](https://golang.org/cmd/go/) !!, [go vet](https://golang.org/cmd/vet/) !!, [golint](https://godoc.org/github.com/golang/lint), [gotype](https://godoc.org/golang.org/x/tools/cmd/gotype) !!, [gometalinter](https://github.com/alecthomas/gometalinter) !!, [go build](https://golang.org/cmd/go/) !!, [gosimple](https://github.com/dominikh/go-tools/tree/master/cmd/gosimple) !!, [staticcheck](https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck) !!, [golangserver](https://github.com/sourcegraph/go-langserver), [golangci-lint](https://github.com/golangci/golangci-lint) !!, [bingo](https://github.com/saibing/bingo) |
| GraphQL | [eslint](http://eslint.org/), [gqlint](https://github.com/happylinks/gqlint), [prettier](https://github.com/prettier/prettier) | | GraphQL | [eslint](http://eslint.org/), [gqlint](https://github.com/happylinks/gqlint), [prettier](https://github.com/prettier/prettier) |
| Hack | [hack](http://hacklang.org/), [hackfmt](https://github.com/facebook/hhvm/tree/master/hphp/hack/hackfmt), [hhast](https://github.com/hhvm/hhast) (disabled by default; see `:help ale-integration-hack`) | | Hack | [hack](http://hacklang.org/), [hackfmt](https://github.com/facebook/hhvm/tree/master/hphp/hack/hackfmt), [hhast](https://github.com/hhvm/hhast) (disabled by default; see `:help ale-integration-hack`) |
| Haml | [haml-lint](https://github.com/brigade/haml-lint) | | Haml | [haml-lint](https://github.com/brigade/haml-lint) |

29
ale_linters/go/bingo.vim Normal file
View File

@ -0,0 +1,29 @@
" Author: Jerko Steiner <https://github.com/jeremija>
" Description: https://github.com/saibing/bingo
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'))
endfunction
function! ale_linters#go#bingo#FindProjectRoot(buffer) abort
let l:project_root = ale#path#FindNearestFile(a:buffer, 'go.mod')
let l:mods = ':h'
if empty(l:project_root)
let l:project_root = ale#path#FindNearestDirectory(a:buffer, '.git')
let l:mods = ':h:h'
endif
return !empty(l:project_root) ? fnamemodify(l:project_root, l:mods) : ''
endfunction
call ale#linter#Define('go', {
\ 'name': 'bingo',
\ 'lsp': 'stdio',
\ 'executable_callback': ale#VarFunc('go_bingo_executable'),
\ 'command_callback': 'ale_linters#go#bingo#GetCommand',
\ 'project_root_callback': 'ale_linters#go#bingo#FindProjectRoot',
\})

View File

@ -7,7 +7,7 @@ Integration Information
The `gometalinter` linter is disabled by default. ALE enables `gofmt`, The `gometalinter` linter is disabled by default. ALE enables `gofmt`,
`golint` and `go vet` by default. It also supports `staticcheck`, `go `golint` and `go vet` by default. It also supports `staticcheck`, `go
build`, `gosimple`, and `golangserver`. build`, `gosimple`, `golangserver`.
To enable `gometalinter`, update |g:ale_linters| as appropriate: To enable `gometalinter`, update |g:ale_linters| as appropriate:
> >
@ -195,5 +195,21 @@ g:ale_go_golangci_lint_package *g:ale_go_golangci_lint_package*
current file. current file.
===============================================================================
bingo *ale-go-bingo*
g:ale_go_bingo_executable *g:ale_go_bingo_executable*
*b:ale_go_bingo_executable*
Type: |String|
Default: `'go-bingo'`
Location of the go-bingo binary file.
g:ale_go_bingo_options *g:ale_go_bingo_options*
*b:ale_go_bingo_options*
Type: |String|
Default: `''`
=============================================================================== ===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -118,6 +118,7 @@ CONTENTS *ale-contents*
staticcheck.........................|ale-go-staticcheck| staticcheck.........................|ale-go-staticcheck|
golangserver........................|ale-go-golangserver| golangserver........................|ale-go-golangserver|
golangci-lint.......................|ale-go-golangci-lint| golangci-lint.......................|ale-go-golangci-lint|
bingo...............................|ale-go-bingo|
graphql...............................|ale-graphql-options| graphql...............................|ale-graphql-options|
eslint..............................|ale-graphql-eslint| eslint..............................|ale-graphql-eslint|
gqlint..............................|ale-graphql-gqlint| gqlint..............................|ale-graphql-gqlint|
@ -438,7 +439,7 @@ Notes:
* FusionScript: `fusion-lint` * FusionScript: `fusion-lint`
* Git Commit Messages: `gitlint` * Git Commit Messages: `gitlint`
* GLSL: glslang, `glslls` * GLSL: glslang, `glslls`
* Go: `gofmt`, `goimports`, `go mod`!!, `go vet`!!, `golint`, `gotype`!!, `gometalinter`!!, `go build`!!, `gosimple`!!, `staticcheck`!!, `golangserver`, `golangci-lint`!! * Go: `gofmt`, `goimports`, `go mod`!!, `go vet`!!, `golint`, `gotype`!!, `gometalinter`!!, `go build`!!, `gosimple`!!, `staticcheck`!!, `golangserver`, `golangci-lint`!!, `bingo`
* GraphQL: `eslint`, `gqlint`, `prettier` * GraphQL: `eslint`, `gqlint`, `prettier`
* Hack: `hack`, `hackfmt`, `hhast` * Hack: `hack`, `hackfmt`, `hhast`
* Haml: `haml-lint` * Haml: `haml-lint`

View File

@ -0,0 +1,31 @@
Before:
call ale#assert#SetUpLinterTest('go', 'bingo')
After:
Restore
unlet! b:ale_completion_enabled
call ale#assert#TearDownLinterTest()
Execute(should set correct defaults):
AssertLinter 'bingo', ale#Escape('bingo') . ' --mode stdio'
Execute(should configure bingo callback executable):
let b:ale_go_bingo_executable = 'boo'
let b:ale_go_bingo_options = ''
AssertLinter 'boo', ale#Escape('boo')
Execute(should set bingo options):
call ale#test#SetFilename('go_paths/go1/prj1/file.go')
" let b:ale_completion_enabled = 1
let b:ale_go_bingo_options = ''
AssertLinter 'bingo',
\ ale#Escape('bingo') . ''
let b:ale_go_bingo_options = '--mode stdio --trace'
AssertLinter 'bingo',
\ ale#Escape('bingo') . ' --mode stdio --trace'

View File

@ -0,0 +1,21 @@
Before:
call ale#test#SetDirectory('/testplugin/test')
runtime ale_linters/go/bingo.vim
After:
call ale#test#RestoreDirectory()
call ale#linter#Reset()
Execute(Should return directory for 'go.mod' if found in parent directory):
call ale#test#SetFilename('go_files/test.go')
AssertEqual
\ ale#path#Simplify(g:dir . '/go_files'),
\ ale_linters#go#bingo#FindProjectRoot(bufnr(''))
Execute(Should return nearest directory with '.git' if found in parent directory):
call ale#test#SetFilename('test.go')
AssertEqual
\ fnamemodify(ale#path#Simplify('/testplugin'), ':p:h'),
\ ale_linters#go#bingo#FindProjectRoot(bufnr(''))