diff options
author | Jeremy Cantrell <jmcantrell@gmail.com> | 2022-11-07 07:20:25 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-07 22:20:25 +0900 |
commit | 4b433e5693ccec8e408504c4b139b8f7cc6a4aa3 (patch) | |
tree | 58c6565cbbadc8606fc2d26f5f0761496ce5b7cc | |
parent | edffffac2570cf837badf4195fb3d55ae439af7d (diff) | |
download | ale-4b433e5693ccec8e408504c4b139b8f7cc6a4aa3.zip |
Add raco_fmt fixer for Racket files (#4354)
* Add raco_fmt fixer for Racket files
* Fix command and add test
* Fix quoting
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/raco_fmt.vim | 15 | ||||
-rw-r--r-- | doc/ale-supported-languages-and-tools.txt | 1 | ||||
-rw-r--r-- | supported-tools.md | 1 | ||||
-rw-r--r-- | test/fixers/test_raco_fmt_fixer_callback.vader | 17 |
5 files changed, 39 insertions, 0 deletions
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 <jmcantrell@gmail.com> +" 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} + |