Fix #1392 - Only check files on disk for gotype

This commit is contained in:
w0rp 2018-03-18 17:16:13 +00:00
parent bdd8d2399f
commit c112ee9dff
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
4 changed files with 14 additions and 24 deletions

View File

@ -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), [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) !! |
| 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), [prettier](https://github.com/prettier/prettier) |
| Haml | [haml-lint](https://github.com/brigade/haml-lint) |
| Handlebars | [ember-template-lint](https://github.com/rwjblue/ember-template-lint) |

View File

@ -1,23 +1,19 @@
" Author: Jelte Fennema <github-public@jeltef.nl>
" Description: gotype for Go files
function! ale_linters#go#gotype#GetCommand(buffer) abort
if expand('#' . a:buffer . ':p') =~# '_test\.go$'
return
endif
return 'gotype %s'
endfunction
call ale#linter#Define('go', {
\ 'name': 'gotype',
\ 'output_stream': 'stderr',
\ 'executable': 'gotype',
\ 'command_callback': 'ale_linters#go#gotype#GetCommand',
\ 'callback': 'ale#handlers#unix#HandleAsError',
\ 'lint_file': 1,
\})
"\ '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

View File

@ -327,7 +327,7 @@ Notes:
* FusionScript: `fusion-lint`
* Git Commit Messages: `gitlint`
* GLSL: glslang, `glslls`
* Go: `gofmt`, `goimports`, `go vet`!!, `golint`, `gotype`, `gometalinter`!!, `go build`!!, `gosimple`!!, `staticcheck`!!
* Go: `gofmt`, `goimports`, `go vet`!!, `golint`, `gotype`!!, `gometalinter`!!, `go build`!!, `gosimple`!!, `staticcheck`!!
* GraphQL: `eslint`, `gqlint`, `prettier`
* Haml: `haml-lint`
* Handlebars: `ember-template-lint`

View File

@ -5,15 +5,9 @@ Before:
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 default gotype command should be correct):
AssertEqual 'gotype %s', 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(''))
AssertEqual 0, ale_linters#go#gotype#GetCommand(bufnr(''))