From 634eb1920cf6f22bf5a121928511ad873656b819 Mon Sep 17 00:00:00 2001 From: Ahmed El Gabri Date: Sun, 29 Oct 2017 16:27:52 +0100 Subject: [PATCH] refmt fixer for ReasonML --- README.md | 2 +- autoload/ale/fix/registry.vim | 5 +++ autoload/ale/fixers/refmt.vim | 18 +++++++++ doc/ale-reasonml.txt | 16 ++++++++ doc/ale.txt | 3 +- test/fixers/test_refmt_fixer_callback.vader | 41 +++++++++++++++++++++ test/reasonml_files/testfile.re | 0 7 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 autoload/ale/fixers/refmt.vim create mode 100644 test/fixers/test_refmt_fixer_callback.vader create mode 100644 test/reasonml_files/testfile.re diff --git a/README.md b/README.md index adf4965..6e5ef26 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ formatting. | Puppet | [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) | | Python | [autopep8](https://github.com/hhatto/autopep8), [flake8](http://flake8.pycqa.org/en/latest/), [isort](https://github.com/timothycrosley/isort), [mypy](http://mypy-lang.org/), [pycodestyle](https://github.com/PyCQA/pycodestyle), [pylint](https://www.pylint.org/) !!, [yapf](https://github.com/google/yapf) | | R | [lintr](https://github.com/jimhester/lintr) | -| ReasonML | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-integration-reason-merlin` for configuration instructions | +| ReasonML | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-integration-reason-merlin` for configuration instructions, [refmt](https://github.com/reasonml/reason-cli) | | reStructuredText | [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | | RPM spec | [rpmlint](https://github.com/rpm-software-management/rpmlint) (disabled by default; see `:help ale-integration-spec`) | | Ruby | [brakeman](http://brakemanscanner.org/) !!, [rails_best_practices](https://github.com/flyerhzm/rails_best_practices) !!, [reek](https://github.com/troessner/reek), [rubocop](https://github.com/bbatsov/rubocop), [ruby](https://www.ruby-lang.org) | diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 5aa78ac..37bbee9 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -127,6 +127,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['haskell'], \ 'description': 'Fix Haskell files with hfmt.', \ }, +\ 'refmt': { +\ 'function': 'ale#fixers#refmt#Fix', +\ 'suggested_filetypes': ['reason'], +\ 'description': 'Fix ReasonML files with refmt.', +\ }, \} " Reset the function registry to the default entries. diff --git a/autoload/ale/fixers/refmt.vim b/autoload/ale/fixers/refmt.vim new file mode 100644 index 0000000..514f950 --- /dev/null +++ b/autoload/ale/fixers/refmt.vim @@ -0,0 +1,18 @@ +" Author: Ahmed El Gabri <@ahmedelgabri> +" Description: Integration of refmt with ALE. + +call ale#Set('reasonml_refmt_executable', 'refmt') +call ale#Set('reasonml_refmt_options', '') + +function! ale#fixers#refmt#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'reasonml_refmt_executable') + let l:options = ale#Var(a:buffer, 'reasonml_refmt_options') + + return { + \ 'command': ale#Escape(l:executable) + \ . (empty(l:options) ? '' : ' ' . l:options) + \ . ' --in-place' + \ . ' %t', + \ 'read_temporary_file': 1, + \} +endfunction diff --git a/doc/ale-reasonml.txt b/doc/ale-reasonml.txt index 17a7b2e..d533d85 100644 --- a/doc/ale-reasonml.txt +++ b/doc/ale-reasonml.txt @@ -10,6 +10,22 @@ merlin *ale-reasonml-merlin* detailed instructions (https://github.com/the-lambda-church/merlin/wiki/vim-from-scratch). +=============================================================================== +refmt *ale-reasonml-refmt* + +g:ale_reasonml_refmt_executable *g:ale_reasonml_refmt_executable* + *b:ale_reasonml_refmt_executable* + Type: |String| + Default: `'refmt'` + + This variable can be set to pass the path of the refmt fixer. + +g:ale_reasonml_refmt_options *g:ale_reasonml_refmt_options* + *b:ale_reasonml_refmt_options* + Type: |String| + Default: `''` + + This variable can be set to pass additional options to the refmt fixer. =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 2026978..58a58e3 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -150,6 +150,7 @@ CONTENTS *ale-contents* lintr...............................|ale-r-lintr| reasonml..............................|ale-reasonml-options| merlin..............................|ale-reasonml-merlin| + refmt...............................|ale-reasonml-refmt| restructuredtext......................|ale-restructuredtext-options| write-good..........................|ale-restructuredtext-write-good| ruby..................................|ale-ruby-options| @@ -308,7 +309,7 @@ Notes: * Puppet: `puppet`, `puppet-lint` * Python: `autopep8`, `flake8`, `isort`, `mypy`, `pycodestyle`, `pylint`!!, `yapf` * R: `lintr` -* ReasonML: `merlin` +* ReasonML: `merlin`, `refmt` * reStructuredText: `proselint`, `write-good` * RPM spec: `rpmlint` * Ruby: `brakeman`, `rails_best_practices`!!, `reek`, `rubocop`, `ruby` diff --git a/test/fixers/test_refmt_fixer_callback.vader b/test/fixers/test_refmt_fixer_callback.vader new file mode 100644 index 0000000..9ec331e --- /dev/null +++ b/test/fixers/test_refmt_fixer_callback.vader @@ -0,0 +1,41 @@ +Before: + Save g:ale_reasonml_refmt_executable + Save g:ale_reasonml_refmt_options + + " Use an invalid global executable, so we don't match it. + let g:ale_reasonml_refmt_executable = 'xxxinvalid' + let g:ale_reasonml_refmt_options = '' + + call ale#test#SetDirectory('/testplugin/test/fixers') + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The refmt callback should return the correct default values): + call ale#test#SetFilename('../reasonml_files/testfile.re') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape('xxxinvalid') + \ . ' --in-place' + \ . ' %t', + \ }, + \ ale#fixers#refmt#Fix(bufnr('')) + +Execute(The refmt callback should include custom refmt options): + let g:ale_reasonml_refmt_options = "-w 80" + call ale#test#SetFilename('../reasonml_files/testfile.re') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape('xxxinvalid') + \ . ' ' . g:ale_reasonml_refmt_options + \ . ' --in-place' + \ . ' %t', + \ }, + \ ale#fixers#refmt#Fix(bufnr('')) + diff --git a/test/reasonml_files/testfile.re b/test/reasonml_files/testfile.re new file mode 100644 index 0000000..e69de29