Go: Add gotype support (#1099)
This commit is contained in:
parent
c9d66b861b
commit
b6d1c41925
6 changed files with 51 additions and 2 deletions
|
@ -104,7 +104,7 @@ formatting.
|
|||
| FusionScript | [fusion-lint](https://github.com/RyanSquared/fusionscript) |
|
||||
| Git Commit Messages | [gitlint](https://github.com/jorisroovers/gitlint) |
|
||||
| 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 vet](https://golang.org/cmd/vet/), [golint](https://godoc.org/github.com/golang/lint), [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) !! |
|
||||
| Go | [gofmt](https://golang.org/cmd/gofmt/), [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports), [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) !! |
|
||||
| GraphQL | [eslint](http://eslint.org/), [gqlint](https://github.com/happylinks/gqlint) |
|
||||
| Haml | [haml-lint](https://github.com/brigade/haml-lint) |
|
||||
| Handlebars | [ember-template-lint](https://github.com/rwjblue/ember-template-lint) |
|
||||
|
|
23
ale_linters/go/gotype.vim
Normal file
23
ale_linters/go/gotype.vim
Normal file
|
@ -0,0 +1,23 @@
|
|||
" Author: Jelte Fennema <github-public@jeltef.nl>
|
||||
" Description: gotype for Go files
|
||||
|
||||
call ale#linter#Define('go', {
|
||||
\ 'name': 'gotype',
|
||||
\ 'output_stream': 'stderr',
|
||||
\ 'executable': 'gotype',
|
||||
\ 'command_callback': 'ale_linters#go#gotype#GetCommand',
|
||||
\ 'callback': 'ale#handlers#unix#HandleAsError',
|
||||
\})
|
||||
|
||||
"\ 'command':
|
||||
function! ale_linters#go#gotype#GetCommand(buffer) abort
|
||||
let l:cur_file = expand('#' . a:buffer . ':p')
|
||||
if l:cur_file =~# '_test\.go$'
|
||||
return
|
||||
endif
|
||||
|
||||
let l:module_files = globpath(expand('#' . a:buffer . ':p:h'), '*.go', 0, 1)
|
||||
let l:other_module_files = filter(l:module_files, 'v:val isnot# ' . ale#util#EscapeVim(l:cur_file) . ' && v:val !~# "_test\.go$"')
|
||||
return 'gotype %t ' . join(map(l:other_module_files, 'ale#Escape(v:val)'))
|
||||
|
||||
endfunction
|
|
@ -236,6 +236,13 @@ function! ale#util#EscapePCRE(unsafe_string) abort
|
|||
return substitute(a:unsafe_string, '\([\-\[\]{}()*+?.^$|]\)', '\\\1', 'g')
|
||||
endfunction
|
||||
|
||||
" Escape a string so that it can be used as a literal string inside an evaled
|
||||
" vim command.
|
||||
function! ale#util#EscapeVim(unsafe_string) abort
|
||||
return "'" . substitute(a:unsafe_string, "'", "''", 'g') . "'"
|
||||
endfunction
|
||||
|
||||
|
||||
" Given a String or a List of String values, try and decode the string(s)
|
||||
" as a JSON value which can be decoded with json_decode. If the JSON string
|
||||
" is invalid, the default argument value will be returned instead.
|
||||
|
|
|
@ -309,7 +309,7 @@ Notes:
|
|||
* FusionScript: `fusion-lint`
|
||||
* Git Commit Messages: `gitlint`
|
||||
* GLSL: glslang, `glslls`
|
||||
* Go: `gofmt`, `goimports`, `go vet`, `golint`, `gometalinter`!!, `go build`!!, `gosimple`!!, `staticcheck`!!
|
||||
* Go: `gofmt`, `goimports`, `go vet`, `golint`, `gotype`, `gometalinter`!!, `go build`!!, `gosimple`!!, `staticcheck`!!
|
||||
* GraphQL: `eslint`, `gqlint`
|
||||
* Haml: `haml-lint`
|
||||
* Handlebars: `ember-template-lint`
|
||||
|
|
19
test/command_callback/test_gotype_command_callback.vader
Normal file
19
test/command_callback/test_gotype_command_callback.vader
Normal file
|
@ -0,0 +1,19 @@
|
|||
Before:
|
||||
runtime ale_linters/go/gotype.vim
|
||||
call ale#test#SetFilename('../go_files/testfile2.go')
|
||||
|
||||
After:
|
||||
call ale#linter#Reset()
|
||||
|
||||
|
||||
Execute(The gotype callback should include other files from the directory but exclude the file itself):
|
||||
let dir = expand('#' . bufnr('') . ':p:h')
|
||||
AssertEqual
|
||||
\ "gotype %t ". ale#Escape(ale#path#Simplify(dir . "/testfile.go")),
|
||||
\ ale_linters#go#gotype#GetCommand(bufnr(''))
|
||||
|
||||
Execute(The gotype callback should ignore test files):
|
||||
call ale#test#SetFilename('bla_test.go')
|
||||
AssertEqual
|
||||
\ 0,
|
||||
\ ale_linters#go#gotype#GetCommand(bufnr(''))
|
0
test/go_files/testfile2.go
Normal file
0
test/go_files/testfile2.go
Normal file
Reference in a new issue