summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2017-10-24 22:13:04 +0100
committerGitHub <noreply@github.com>2017-10-24 22:13:04 +0100
commit0e4dd95e5dac4ef5ac7877b1885f1c8300a53bd3 (patch)
tree6c9706548e6c7d9f393526c851907d8f313961d8
parent5a91f7e19f1eab027bfd93098d80e1cdd847f918 (diff)
parentbe1377f6d7e642a8b56bb0589dc9cc48fc836c13 (diff)
downloadale-0e4dd95e5dac4ef5ac7877b1885f1c8300a53bd3.zip
Merge pull request #1017 from carakan/elixir_format
`mix format` new fixer for elixir lang
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/mix_format.vim16
-rw-r--r--doc/ale-elixir.txt17
-rw-r--r--doc/ale.txt2
-rw-r--r--test/elixir-test-files/testfile.ex0
-rw-r--r--test/fixers/test_mix_format_fixer_callback.vader20
6 files changed, 60 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index d26c71ab..598be6d0 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.',
\ },
+\ 'mix_format': {
+\ 'function': 'ale#fixers#mix_format#Fix',
+\ 'suggested_filetypes': ['elixir'],
+\ 'description': 'Apply mix format to a file.',
+\ },
\ 'format': {
\ 'function': 'ale#fixers#format#Fix',
\ 'suggested_filetypes': ['elm'],
diff --git a/autoload/ale/fixers/mix_format.vim b/autoload/ale/fixers/mix_format.vim
new file mode 100644
index 00000000..04866408
--- /dev/null
+++ b/autoload/ale/fixers/mix_format.vim
@@ -0,0 +1,16 @@
+" Author: carakan <carakan@gmail.com>
+" Description: Fixing files with elixir formatter 'mix format'.
+
+call ale#Set('elixir_mix_executable', 'mix')
+
+function! ale#fixers#mix_format#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'elixir_mix_executable')
+endfunction
+
+function! ale#fixers#mix_format#Fix(buffer) abort
+ return {
+ \ 'command': ale#Escape(ale#fixers#mix_format#GetExecutable(a:buffer))
+ \ . ' format %t',
+ \ 'read_temporary_file': 1,
+ \}
+endfunction
diff --git a/doc/ale-elixir.txt b/doc/ale-elixir.txt
new file mode 100644
index 00000000..a5318c0f
--- /dev/null
+++ b/doc/ale-elixir.txt
@@ -0,0 +1,17 @@
+===============================================================================
+ALE Elixir Integration *ale-elixir-options*
+
+
+===============================================================================
+mix *ale-elixir-mix*
+
+g:ale_elixir_mix_options *g:ale_elixir_mix_options*
+ *b:ale_elixir_mix_options*
+ Type: |String|
+ Default: `'mix'`
+
+
+ This variable can be changed to specify the mix executable.
+
+===============================================================================
+ vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
diff --git a/doc/ale.txt b/doc/ale.txt
index fb0b5a76..b764fe6b 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -48,6 +48,8 @@ CONTENTS *ale-contents*
dartanalyzer........................|ale-dart-dartanalyzer|
dockerfile............................|ale-dockerfile-options|
hadolint............................|ale-dockerfile-hadolint|
+ elixir................................|ale-elixir-options|
+ mix.................................|ale-elixir-mix|
elm...................................|ale-elm-options|
elm-format..........................|ale-elm-elm-format|
elm-make............................|ale-elm-elm-make|
diff --git a/test/elixir-test-files/testfile.ex b/test/elixir-test-files/testfile.ex
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/elixir-test-files/testfile.ex
diff --git a/test/fixers/test_mix_format_fixer_callback.vader b/test/fixers/test_mix_format_fixer_callback.vader
new file mode 100644
index 00000000..c6c97c57
--- /dev/null
+++ b/test/fixers/test_mix_format_fixer_callback.vader
@@ -0,0 +1,20 @@
+Before:
+ call ale#test#SetDirectory('/testplugin/test/fixers')
+ Save g:ale_elixir_mix_executable
+
+ let g:ale_elixir_mix_executable = 'xxxinvalid'
+
+After:
+ call ale#test#RestoreDirectory()
+
+Execute(The mix_format callback should return the correct default values):
+ call ale#test#SetFilename('../elixir-test-files/testfile.ex')
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command': ale#Escape('xxxinvalid')
+ \ . ' format %t',
+ \ },
+ \ ale#fixers#mix_format#Fix(bufnr(''))
+