From 43653ef54816e5219de56cf57073a93b4ce957b8 Mon Sep 17 00:00:00 2001 From: Carlos Ramos Date: Fri, 20 Oct 2017 17:13:25 -0400 Subject: [PATCH] new fixer elixir mix format (only available in elixir > 1.6) --- autoload/ale/fix/registry.vim | 5 +++++ autoload/ale/fixers/mix_format.vim | 17 +++++++++++++++++ autoload/ale/handlers/elixir.vim | 5 +++++ test/elixir-test-files/testfile.ex | 0 test/fixers/test_elixir_fixer_callback.vader | 16 ++++++++++++++++ 5 files changed, 43 insertions(+) create mode 100644 autoload/ale/fixers/mix_format.vim create mode 100644 autoload/ale/handlers/elixir.vim create mode 100644 test/elixir-test-files/testfile.ex create mode 100644 test/fixers/test_elixir_fixer_callback.vader 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..905a6089 --- /dev/null +++ b/autoload/ale/fixers/mix_format.vim @@ -0,0 +1,17 @@ +" Author: carakan +" 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#handlers#elixir#GetExecutable(a:buffer) + \ . ale#fixers#mix_format#GetExecutable(a:buffer) + \ . ' format %t', + \ 'read_temporary_file': 1, + \} +endfunction diff --git a/autoload/ale/handlers/elixir.vim b/autoload/ale/handlers/elixir.vim new file mode 100644 index 00000000..be25d331 --- /dev/null +++ b/autoload/ale/handlers/elixir.vim @@ -0,0 +1,5 @@ +call ale#Set('elixir_executable', '') + +function! ale#handlers#elixir#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'elixir_executable') +endfunction diff --git a/test/elixir-test-files/testfile.ex b/test/elixir-test-files/testfile.ex new file mode 100644 index 00000000..e69de29b diff --git a/test/fixers/test_elixir_fixer_callback.vader b/test/fixers/test_elixir_fixer_callback.vader new file mode 100644 index 00000000..ff4786e7 --- /dev/null +++ b/test/fixers/test_elixir_fixer_callback.vader @@ -0,0 +1,16 @@ +Before: + call ale#test#SetDirectory('/testplugin/test/fixers') + +After: + call ale#test#RestoreDirectory() + +Execute(The executable path should be correct): + call ale#test#SetFilename('../elixir-test-files/testfile.ex') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': 'mix format' + \ . ' %t', + \ }, + \ ale#fixers#elixir#Fix(bufnr(''))