mirror of https://github.com/dense-analysis/ale
Added support for goimports fixer (#1123)
* Added support for goimports fixer * added test and executable check * fixed test assertions to reflect executable check
This commit is contained in:
parent
16e7dc2371
commit
20a01404f3
|
@ -97,7 +97,7 @@ formatting.
|
||||||
| Fortran | [gcc](https://gcc.gnu.org/) |
|
| Fortran | [gcc](https://gcc.gnu.org/) |
|
||||||
| FusionScript | [fusion-lint](https://github.com/RyanSquared/fusionscript) |
|
| FusionScript | [fusion-lint](https://github.com/RyanSquared/fusionscript) |
|
||||||
| GLSL | [glslang](https://github.com/KhronosGroup/glslang) |
|
| GLSL | [glslang](https://github.com/KhronosGroup/glslang) |
|
||||||
| Go | [gofmt](https://golang.org/cmd/gofmt/), [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), [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 | [gqlint](https://github.com/happylinks/gqlint) |
|
| GraphQL | [gqlint](https://github.com/happylinks/gqlint) |
|
||||||
| Haml | [haml-lint](https://github.com/brigade/haml-lint) |
|
| Haml | [haml-lint](https://github.com/brigade/haml-lint) |
|
||||||
| Handlebars | [ember-template-lint](https://github.com/rwjblue/ember-template-lint) |
|
| Handlebars | [ember-template-lint](https://github.com/rwjblue/ember-template-lint) |
|
||||||
|
|
|
@ -107,6 +107,11 @@ let s:default_registry = {
|
||||||
\ 'suggested_filetypes': ['go'],
|
\ 'suggested_filetypes': ['go'],
|
||||||
\ 'description': 'Fix Go files with go fmt.',
|
\ 'description': 'Fix Go files with go fmt.',
|
||||||
\ },
|
\ },
|
||||||
|
\ 'goimports': {
|
||||||
|
\ 'function': 'ale#fixers#goimports#Fix',
|
||||||
|
\ 'suggested_filetypes': ['go'],
|
||||||
|
\ 'description': 'Fix Go files imports with go fmt.',
|
||||||
|
\ },
|
||||||
\ 'tslint': {
|
\ 'tslint': {
|
||||||
\ 'function': 'ale#fixers#tslint#Fix',
|
\ 'function': 'ale#fixers#tslint#Fix',
|
||||||
\ 'suggested_filetypes': ['typescript'],
|
\ 'suggested_filetypes': ['typescript'],
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
" Author: Jeff Willette <jrwillette88@gmail.com>
|
||||||
|
" Description: Integration of goimports with ALE.
|
||||||
|
|
||||||
|
call ale#Set('go_goimports_executable', 'goimports')
|
||||||
|
call ale#Set('go_goimports_options', '')
|
||||||
|
|
||||||
|
function! ale#fixers#goimports#Fix(buffer) abort
|
||||||
|
let l:executable = ale#Var(a:buffer, 'go_goimports_executable')
|
||||||
|
let l:options = ale#Var(a:buffer, 'go_goimports_options')
|
||||||
|
|
||||||
|
if !executable(l:executable)
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
return {
|
||||||
|
\ 'command': ale#Escape(l:executable)
|
||||||
|
\ . ' -l -w'
|
||||||
|
\ . (empty(l:options) ? '' : ' ' . l:options)
|
||||||
|
\ . ' %t',
|
||||||
|
\ 'read_temporary_file': 1,
|
||||||
|
\}
|
||||||
|
endfunction
|
|
@ -287,7 +287,7 @@ Notes:
|
||||||
* Fortran: `gcc`
|
* Fortran: `gcc`
|
||||||
* FusionScript: `fusion-lint`
|
* FusionScript: `fusion-lint`
|
||||||
* GLSL: glslang
|
* GLSL: glslang
|
||||||
* Go: `gofmt`, `go vet`, `golint`, `gometalinter`!!, `go build`!!, `gosimple`!!, `staticcheck`!!
|
* Go: `gofmt`, `goimports`, `go vet`, `golint`, `gometalinter`!!, `go build`!!, `gosimple`!!, `staticcheck`!!
|
||||||
* GraphQL: `gqlint`
|
* GraphQL: `gqlint`
|
||||||
* Haml: `haml-lint`
|
* Haml: `haml-lint`
|
||||||
* Handlebars: `ember-template-lint`
|
* Handlebars: `ember-template-lint`
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
Before:
|
||||||
|
Save g:ale_go_goimports_executable
|
||||||
|
Save g:ale_go_goimports_options
|
||||||
|
|
||||||
|
" Use an invalid global executable, so we don't match it.
|
||||||
|
let g:ale_go_goimports_executable = 'xxxinvalid'
|
||||||
|
let g:ale_go_goimports_options = ''
|
||||||
|
|
||||||
|
call ale#test#SetDirectory('/testplugin/test/fixers')
|
||||||
|
|
||||||
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
|
Execute(The goimports callback should return 0 with bad executable):
|
||||||
|
call ale#test#SetFilename('../go_files/testfile.go')
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ 0,
|
||||||
|
\ ale#fixers#goimports#Fix(bufnr(''))
|
||||||
|
|
Loading…
Reference in New Issue