diff options
author | aliou <aliou@users.noreply.github.com> | 2017-10-03 19:54:35 +0200 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2017-10-03 18:54:35 +0100 |
commit | e376f0ae44f0656021a8c8945212dc27105b34fe (patch) | |
tree | 0069e4df1b6804c221b426e6bac4193dfed77e33 /autoload | |
parent | 3ab414de1a9591b3c3545124329645ec4621cc60 (diff) | |
download | ale-e376f0ae44f0656021a8c8945212dc27105b34fe.zip |
gofmt fixer for Go (#970)
Add a gofmt fixer for golang.
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/gofmt.vim | 18 |
2 files changed, 23 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index e87b02f5..9569d215 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -92,6 +92,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['c', 'cpp'], \ 'description': 'Fix C/C++ files with clang-format.', \ }, +\ 'gofmt': { +\ 'function': 'ale#fixers#gofmt#Fix', +\ 'suggested_filetypes': ['go'], +\ 'description': 'Fix Go files with go fmt.', +\ }, \} " Reset the function registry to the default entries. diff --git a/autoload/ale/fixers/gofmt.vim b/autoload/ale/fixers/gofmt.vim new file mode 100644 index 00000000..66b67a9e --- /dev/null +++ b/autoload/ale/fixers/gofmt.vim @@ -0,0 +1,18 @@ +" Author: aliou <code@aliou.me> +" Description: Integration of gofmt with ALE. + +call ale#Set('go_gofmt_executable', 'gofmt') +call ale#Set('go_gofmt_options', '') + +function! ale#fixers#gofmt#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'go_gofmt_executable') + let l:options = ale#Var(a:buffer, 'go_gofmt_options') + + return { + \ 'command': ale#Escape(l:executable) + \ . ' -l -w' + \ . (empty(l:options) ? '' : ' ' . l:options) + \ . ' %t', + \ 'read_temporary_file': 1, + \} +endfunction |