refmt fixer for ReasonML

This commit is contained in:
Ahmed El Gabri 2017-10-29 16:27:52 +01:00
parent 1aa737cdc9
commit 634eb1920c
No known key found for this signature in database
GPG Key ID: AC977998CD4ACABB
7 changed files with 83 additions and 2 deletions

View File

@ -126,7 +126,7 @@ formatting.
| Puppet | [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) | | 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) | | 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) | | 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) | | 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`) | | 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) | | 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) |

View File

@ -127,6 +127,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['haskell'], \ 'suggested_filetypes': ['haskell'],
\ 'description': 'Fix Haskell files with hfmt.', \ '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. " Reset the function registry to the default entries.

View File

@ -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

View File

@ -10,6 +10,22 @@ merlin *ale-reasonml-merlin*
detailed instructions detailed instructions
(https://github.com/the-lambda-church/merlin/wiki/vim-from-scratch). (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: vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -150,6 +150,7 @@ CONTENTS *ale-contents*
lintr...............................|ale-r-lintr| lintr...............................|ale-r-lintr|
reasonml..............................|ale-reasonml-options| reasonml..............................|ale-reasonml-options|
merlin..............................|ale-reasonml-merlin| merlin..............................|ale-reasonml-merlin|
refmt...............................|ale-reasonml-refmt|
restructuredtext......................|ale-restructuredtext-options| restructuredtext......................|ale-restructuredtext-options|
write-good..........................|ale-restructuredtext-write-good| write-good..........................|ale-restructuredtext-write-good|
ruby..................................|ale-ruby-options| ruby..................................|ale-ruby-options|
@ -308,7 +309,7 @@ Notes:
* Puppet: `puppet`, `puppet-lint` * Puppet: `puppet`, `puppet-lint`
* Python: `autopep8`, `flake8`, `isort`, `mypy`, `pycodestyle`, `pylint`!!, `yapf` * Python: `autopep8`, `flake8`, `isort`, `mypy`, `pycodestyle`, `pylint`!!, `yapf`
* R: `lintr` * R: `lintr`
* ReasonML: `merlin` * ReasonML: `merlin`, `refmt`
* reStructuredText: `proselint`, `write-good` * reStructuredText: `proselint`, `write-good`
* RPM spec: `rpmlint` * RPM spec: `rpmlint`
* Ruby: `brakeman`, `rails_best_practices`!!, `reek`, `rubocop`, `ruby` * Ruby: `brakeman`, `rails_best_practices`!!, `reek`, `rubocop`, `ruby`

View File

@ -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(''))

View File