diff options
author | Jeff Willette <jrwillette88@gmail.com> | 2017-11-15 02:37:22 +0900 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2017-11-14 17:37:22 +0000 |
commit | 20a01404f346f6c633f15b6c5ca45279259f2c5d (patch) | |
tree | 9f71684198931b191a838f71223811fa5cbc706d /autoload | |
parent | 16e7dc2371f908204e5191c0e9d55626352097af (diff) | |
download | ale-20a01404f346f6c633f15b6c5ca45279259f2c5d.zip |
Added support for goimports fixer (#1123)
* Added support for goimports fixer
* added test and executable check
* fixed test assertions to reflect executable check
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/goimports.vim | 22 |
2 files changed, 27 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 24166da7..4ecdae9a 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -107,6 +107,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['go'], \ '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': { \ 'function': 'ale#fixers#tslint#Fix', \ 'suggested_filetypes': ['typescript'], diff --git a/autoload/ale/fixers/goimports.vim b/autoload/ale/fixers/goimports.vim new file mode 100644 index 00000000..f5695136 --- /dev/null +++ b/autoload/ale/fixers/goimports.vim @@ -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 |