summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément DOUIN <clement.douin@gmail.com>2017-09-09 22:30:20 +0200
committerw0rp <w0rp@users.noreply.github.com>2017-09-09 21:30:20 +0100
commitf3da8f45c15fdd335593be060c0c6aaea751e81d (patch)
tree4c7f3161dfb816ae29e5befc9de5bd869e67aadd
parentb3a9a0e3e8264cf8ce7c4d3780b06ab62d0db287 (diff)
downloadale-f3da8f45c15fdd335593be060c0c6aaea751e81d.zip
Add elm-format as a new fixer (#916)
* Add elm-format as a new fixer
-rw-r--r--README.md2
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/format.vim23
-rw-r--r--doc/ale-elm.txt32
-rw-r--r--doc/ale.txt2
-rw-r--r--test/elm-test-files/node_modules/.bin/elm-format0
-rw-r--r--test/elm-test-files/src/subdir/testfile.elm0
-rw-r--r--test/fixers/test_elm_format_fixer_callback.vader75
8 files changed, 137 insertions, 2 deletions
diff --git a/README.md b/README.md
index e808d824..4919564e 100644
--- a/README.md
+++ b/README.md
@@ -87,7 +87,7 @@ formatting.
| Dart | [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) |
| Dockerfile | [hadolint](https://github.com/lukasmartinelli/hadolint) |
| Elixir | [credo](https://github.com/rrrene/credo), [dogma](https://github.com/lpil/dogma) !! |
-| Elm | [elm-make](https://github.com/elm-lang/elm-make) |
+| Elm | [elm-make](https://github.com/elm-lang/elm-make), [elm-format](https://github.com/avh4/elm-format) |
| Erb | [erb](https://github.com/jeremyevans/erubi), [erubis](https://github.com/kwatch/erubis) |
| Erlang | [erlc](http://erlang.org/doc/man/erlc.html), [SyntaxErl](https://github.com/ten0s/syntaxerl) |
| Fortran | [gcc](https://gcc.gnu.org/) |
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 5b1030d9..e87b02f5 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -27,6 +27,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['javascript', 'typescript'],
\ 'description': 'Apply eslint --fix to a file.',
\ },
+\ 'format': {
+\ 'function': 'ale#fixers#format#Fix',
+\ 'suggested_filetypes': ['elm'],
+\ 'description': 'Apply elm-format to a file.',
+\ },
\ 'isort': {
\ 'function': 'ale#fixers#isort#Fix',
\ 'suggested_filetypes': ['python'],
diff --git a/autoload/ale/fixers/format.vim b/autoload/ale/fixers/format.vim
new file mode 100644
index 00000000..be130f00
--- /dev/null
+++ b/autoload/ale/fixers/format.vim
@@ -0,0 +1,23 @@
+" Author: soywod <clement.douin@gmail.com>
+" Description: Integration of elm-format with ALE.
+
+call ale#Set('elm_format_executable', 'elm-format')
+call ale#Set('elm_format_use_global', 0)
+call ale#Set('elm_format_options', '--yes')
+
+function! ale#fixers#format#GetExecutable(buffer) abort
+ return ale#node#FindExecutable(a:buffer, 'elm_format', [
+ \ 'node_modules/.bin/elm-format',
+ \])
+endfunction
+
+function! ale#fixers#format#Fix(buffer) abort
+ let l:options = ale#Var(a:buffer, 'elm_format_options')
+
+ return {
+ \ 'command': ale#Escape(ale#fixers#format#GetExecutable(a:buffer))
+ \ . ' %t'
+ \ . (empty(l:options) ? '' : ' ' . l:options),
+ \ 'read_temporary_file': 1,
+ \}
+endfunction
diff --git a/doc/ale-elm.txt b/doc/ale-elm.txt
new file mode 100644
index 00000000..9331575b
--- /dev/null
+++ b/doc/ale-elm.txt
@@ -0,0 +1,32 @@
+===============================================================================
+ALE Elm Integration *ale-elm-options*
+
+
+===============================================================================
+elm-format *ale-elm-format*
+
+g:ale_elm_format_executable *g:ale_elm_format_executable*
+ *b:ale_elm_format_executable*
+ Type: |String|
+ Default: `'elm-format'`
+
+ See |ale-integrations-local-executables|
+
+
+g:ale_elm_format_use_global *g:ale_elm_format_use_global*
+ *b:ale_elm_format_use_global*
+ Type: |Number|
+ Default: `0`
+
+ See |ale-integrations-local-executables|
+
+
+g:ale_elm_format_options *g:ale_elm_format_options*
+ *b:ale_elm_format_options*
+ Type: |String|
+ Default: `'--yes'`
+
+ This variable can be set to pass additional options to elm-format.
+
+===============================================================================
+ vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
diff --git a/doc/ale.txt b/doc/ale.txt
index 319c109e..ff02f7a6 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -217,7 +217,7 @@ Notes:
* Dart: `dartanalyzer`
* Dockerfile: `hadolint`
* Elixir: `credo`, `dogma`!!
-* Elm: `elm-make`
+* Elm: `elm-make, elm-format`
* Erb: `erb`, `erubis`
* Erlang: `erlc`, `SyntaxErl`
* Fortran: `gcc`
diff --git a/test/elm-test-files/node_modules/.bin/elm-format b/test/elm-test-files/node_modules/.bin/elm-format
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/elm-test-files/node_modules/.bin/elm-format
diff --git a/test/elm-test-files/src/subdir/testfile.elm b/test/elm-test-files/src/subdir/testfile.elm
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/elm-test-files/src/subdir/testfile.elm
diff --git a/test/fixers/test_elm_format_fixer_callback.vader b/test/fixers/test_elm_format_fixer_callback.vader
new file mode 100644
index 00000000..b8b9ed00
--- /dev/null
+++ b/test/fixers/test_elm_format_fixer_callback.vader
@@ -0,0 +1,75 @@
+Before:
+ call ale#test#SetDirectory('/testplugin/test/fixers')
+
+After:
+ unlet! b:ale_elm_format_executable
+ unlet! b:ale_elm_format_use_global
+ unlet! b:ale_elm_format_options
+
+ call ale#test#RestoreDirectory()
+
+Execute(The elm-format command should have default params):
+ call ale#test#SetFilename('../elm-test-files/src/subdir/testfile.elm')
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command':
+ \ ale#Escape(simplify(g:dir . '/../elm-test-files/node_modules/.bin/elm-format'))
+ \ . ' %t --yes',
+ \ },
+ \ ale#fixers#format#Fix(bufnr(''))
+
+Execute(The elm-format command should manage use_global = 1 param):
+ call ale#test#SetFilename('../elm-test-files/src/subdir/testfile.elm')
+ let b:ale_elm_format_use_global = 1
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command':
+ \ ale#Escape('elm-format')
+ \ . ' %t --yes',
+ \ },
+ \ ale#fixers#format#Fix(bufnr(''))
+
+Execute(The elm-format command should manage executable param):
+ call ale#test#SetFilename('../elm-test-files/src/subdir/testfile.elm')
+ let b:ale_elm_format_use_global = 1
+ let b:ale_elm_format_executable = 'elmformat'
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command':
+ \ ale#Escape('elmformat')
+ \ . ' %t --yes',
+ \ },
+ \ ale#fixers#format#Fix(bufnr(''))
+
+Execute(The elm-format command should manage empty options):
+ call ale#test#SetFilename('../elm-test-files/src/subdir/testfile.elm')
+ let b:ale_elm_format_options = ''
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command':
+ \ ale#Escape(simplify(g:dir . '/../elm-test-files/node_modules/.bin/elm-format'))
+ \ . ' %t',
+ \ },
+ \ ale#fixers#format#Fix(bufnr(''))
+
+Execute(The elm-format command should manage custom options):
+ call ale#test#SetFilename('../elm-test-files/src/subdir/testfile.elm')
+ let b:ale_elm_format_options = '--param1 --param2'
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command':
+ \ ale#Escape(simplify(g:dir . '/../elm-test-files/node_modules/.bin/elm-format'))
+ \ . ' %t --param1 --param2',
+ \ },
+ \ ale#fixers#format#Fix(bufnr(''))
+