summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/fixers/erlfmt.vim21
-rw-r--r--doc/ale-erlang.txt20
-rw-r--r--doc/ale-supported-languages-and-tools.txt2
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md2
-rw-r--r--test/fixers/test_erlfmt_fixer_callback.vader25
6 files changed, 71 insertions, 0 deletions
diff --git a/autoload/ale/fixers/erlfmt.vim b/autoload/ale/fixers/erlfmt.vim
new file mode 100644
index 00000000..e44046f1
--- /dev/null
+++ b/autoload/ale/fixers/erlfmt.vim
@@ -0,0 +1,21 @@
+" Author: AntoineGagne - https://github.com/AntoineGagne
+" Description: Integration of erlfmt with ALE.
+
+call ale#Set('erlang_erlfmt_executable', 'erlfmt')
+call ale#Set('erlang_erlfmt_use_global', get(g:, 'ale_use_global_executables', 0))
+call ale#Set('erlang_erlfmt_options', '')
+
+function! ale#fixers#erlfmt#GetExecutable(buffer) abort
+ return ale#node#FindExecutable(a:buffer, 'erlang_erlfmt', ['erlfmt'])
+endfunction
+
+function! ale#fixers#erlfmt#Fix(buffer) abort
+ let l:options = ale#Var(a:buffer, 'erlang_erlfmt_options')
+ let l:executable = ale#fixers#erlfmt#GetExecutable(a:buffer)
+
+ let l:command = ale#Escape(l:executable) . (empty(l:options) ? '' : ' ' . l:options) . ' %s'
+
+ return {
+ \ 'command': l:command
+ \}
+endfunction
diff --git a/doc/ale-erlang.txt b/doc/ale-erlang.txt
index 93ac7915..ede179d1 100644
--- a/doc/ale-erlang.txt
+++ b/doc/ale-erlang.txt
@@ -72,6 +72,26 @@ g:ale_erlang_erlc_options *g:ale_erlang_erlc_options*
-------------------------------------------------------------------------------
+erlfmt *ale-erlang-erlfmt*
+
+g:ale_erlang_erlfmt_executable *g:ale_erlang_erlfmt_executable*
+ *b:ale_erlang_erlfmt_executable*
+ Type: |String|
+ Default: `'erlfmt'`
+
+ This variable can be changed to specify the erlfmt executable.
+
+
+g:ale_erlang_erlfmt_options *g:ale_erlang_erlfmt_options*
+ *b:ale_erlang_erlfmt_options*
+ Type: |String|
+ Default: `''`
+
+ This variable controls additional parameters passed to `erlfmt`, such as
+ `--insert-pragma` or `--print-width`.
+
+
+-------------------------------------------------------------------------------
syntaxerl *ale-erlang-syntaxerl*
g:ale_erlang_syntaxerl_executable *g:ale_erlang_syntaxerl_executable*
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index cb90de4c..e6764144 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -150,8 +150,10 @@ Notes:
* `ruumba`
* Erlang
* `SyntaxErl`
+ * `dialyzer`
* `elvis`!!
* `erlc`
+ * `erlfmt`
* Fish
* `fish` (-n flag)
* `fish_indent`
diff --git a/doc/ale.txt b/doc/ale.txt
index 113e29c5..1f7dbe76 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2697,6 +2697,7 @@ documented in additional help files.
dialyzer..............................|ale-erlang-dialyzer|
elvis.................................|ale-erlang-elvis|
erlc..................................|ale-erlang-erlc|
+ erlfmt................................|ale-erlang-erlfmt|
syntaxerl.............................|ale-erlang-syntaxerl|
eruby...................................|ale-eruby-options|
ruumba................................|ale-eruby-ruumba|
diff --git a/supported-tools.md b/supported-tools.md
index e9c88e95..a522d748 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -159,8 +159,10 @@ formatting.
* [ruumba](https://github.com/ericqweinstein/ruumba)
* Erlang
* [SyntaxErl](https://github.com/ten0s/syntaxerl)
+ * [dialyzer](http://erlang.org/doc/man/dialyzer.html)
* [elvis](https://github.com/inaka/elvis) :floppy_disk:
* [erlc](http://erlang.org/doc/man/erlc.html)
+ * [erlfmt](https://github.com/WhatsApp/erlfmt)
* Fish
* fish [-n flag](https://linux.die.net/man/1/fish)
* [fish_indent](https://fishshell.com/docs/current/cmds/fish_indent.html)
diff --git a/test/fixers/test_erlfmt_fixer_callback.vader b/test/fixers/test_erlfmt_fixer_callback.vader
new file mode 100644
index 00000000..132cd6ee
--- /dev/null
+++ b/test/fixers/test_erlfmt_fixer_callback.vader
@@ -0,0 +1,25 @@
+Before:
+ Save b:ale_elm_format_executable
+ Save b:ale_elm_format_options
+
+ let b:ale_elm_format_executable = 'erlfmt'
+ let b:ale_elm_format_options = ''
+
+After:
+ Restore
+
+Execute(The erlfmt command should handle empty options):
+ AssertEqual
+ \ {
+ \ 'command': ale#Escape('erlfmt') . ' %s'
+ \ },
+ \ ale#fixers#erlfmt#Fix(bufnr(''))
+
+Execute(The erlfmt command should handle custom options):
+ let b:ale_erlang_erlfmt_options = '--insert-pragma'
+
+ AssertEqual
+ \ {
+ \ 'command': ale#Escape('erlfmt') . ' --insert-pragma %s'
+ \ },
+ \ ale#fixers#erlfmt#Fix(bufnr(''))