diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index f058123e..2062f543 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -570,6 +570,11 @@ let s:default_registry = { \ 'function': 'ale#fixers#zigfmt#Fix', \ 'suggested_filetypes': ['zig'], \ 'description': 'Official formatter for Zig', +\ }, +\ 'raco_fmt': { +\ 'function': 'ale#fixers#raco_fmt#Fix', +\ 'suggested_filetypes': ['racket'], +\ 'description': 'Fix Racket files with raco fmt.', \ } \} diff --git a/autoload/ale/fixers/raco_fmt.vim b/autoload/ale/fixers/raco_fmt.vim new file mode 100644 index 00000000..16cf4468 --- /dev/null +++ b/autoload/ale/fixers/raco_fmt.vim @@ -0,0 +1,15 @@ +" Author: Jeremy Cantrell +" Description: Integration of raco fmt with ALE. + +call ale#Set('racket_raco_fmt_executable', 'raco') +call ale#Set('racket_raco_fmt_options', '') + +function! ale#fixers#raco_fmt#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'racket_raco_fmt_executable') + let l:options = ale#Var(a:buffer, 'racket_raco_fmt_options') + + return { + \ 'command': ale#Escape(l:executable) . ' fmt' + \ . (empty(l:options) ? '' : ' ' . l:options), + \} +endfunction diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 0b34aade..591f1cb3 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -497,6 +497,7 @@ Notes: * Racket * `racket-langserver` * `raco` + * `raco_fmt` * Re:VIEW * `redpen` * ReasonML diff --git a/supported-tools.md b/supported-tools.md index 93d0f2bb..2989bfbc 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -506,6 +506,7 @@ formatting. * Racket * [racket-langserver](https://github.com/jeapostrophe/racket-langserver/tree/master) * [raco](https://docs.racket-lang.org/raco/) + * [raco_fmt](https://docs.racket-lang.org/fmt/) * Re:VIEW * [redpen](http://redpen.cc/) * ReasonML diff --git a/test/fixers/test_raco_fmt_fixer_callback.vader b/test/fixers/test_raco_fmt_fixer_callback.vader new file mode 100644 index 00000000..34c599a3 --- /dev/null +++ b/test/fixers/test_raco_fmt_fixer_callback.vader @@ -0,0 +1,17 @@ +Before: + call ale#assert#SetUpFixerTest('racket', 'raco_fmt') + +After: + call ale#assert#TearDownFixerTest() + +Execute(The raco_fmt callback should return the correct default values): + call ale#test#SetFilename('../test-files/racket/simple-script/foo.rkt') + + AssertFixer {'command': ale#Escape('raco') . ' fmt'} + +Execute(The raco_fmt callback should include custom raco_fmt options): + let g:ale_racket_raco_fmt_options = "--width 100" + call ale#test#SetFilename('../test-files/racket/simple-script/foo.rkt') + + AssertFixer {'command': ale#Escape('raco') . ' fmt ' . g:ale_racket_raco_fmt_options} +