summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Jean Johansen <mathias@mjj.io>2021-07-09 16:54:43 +0200
committerGitHub <noreply@github.com>2021-07-09 23:54:43 +0900
commit1e9f40ff8d6a9d34fc84171e3cd416729b4506ec (patch)
tree1da3e605601c90bf2df06b1f77a4dfd3121c3cd5
parent8b73d98baf0a185886a55a62b8b32f6543f14af4 (diff)
downloadale-1e9f40ff8d6a9d34fc84171e3cd416729b4506ec.zip
Add support for `lua-format` fixer. (#3804)
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/lua_format.vim16
-rw-r--r--doc/ale-lua.txt18
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/fixers/test_lua_format_fixer_callback.vader35
7 files changed, 77 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 0d110c79..728b6df7 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -441,6 +441,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['html', 'htmldjango'],
\ 'description': 'Fix HTML files with html-beautify.',
\ },
+\ 'lua-format': {
+\ 'function': 'ale#fixers#lua_format#Fix',
+\ 'suggested_filetypes': ['lua'],
+\ 'description': 'Fix Lua files with lua-format.',
+\ },
\ 'luafmt': {
\ 'function': 'ale#fixers#luafmt#Fix',
\ 'suggested_filetypes': ['lua'],
diff --git a/autoload/ale/fixers/lua_format.vim b/autoload/ale/fixers/lua_format.vim
new file mode 100644
index 00000000..98b155c0
--- /dev/null
+++ b/autoload/ale/fixers/lua_format.vim
@@ -0,0 +1,16 @@
+" Author: Mathias Jean Johansen <mathias@mjj.io>
+" Description: Integration of LuaFormatter with ALE.
+
+call ale#Set('lua_lua_format_executable', 'lua-format')
+call ale#Set('lua_lua_format_options', '')
+
+function! ale#fixers#lua_format#Fix(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'lua_lua_format_executable')
+ let l:options = ale#Var(a:buffer, 'lua_lua_format_options')
+
+ return {
+ \ 'command': ale#Escape(l:executable)
+ \ . ale#Pad(l:options)
+ \ . ' -i',
+ \}
+endfunction
diff --git a/doc/ale-lua.txt b/doc/ale-lua.txt
index db7c0924..ac92b9ac 100644
--- a/doc/ale-lua.txt
+++ b/doc/ale-lua.txt
@@ -2,6 +2,24 @@
ALE Lua Integration *ale-lua-options*
===============================================================================
+lua-format *ale-lua-lua-format*
+
+g:ale_lua_lua_format_executable *g:ale_lua_lua_format_executable*
+ *b:ale_lua_lua_format_executable*
+ Type: |String|
+ Default: `'lua-format'`
+
+ This variable can be changed to change the path to lua-format.
+
+g:ale_lua_lua_format_options *g:ale_lua_lua_format_options*
+ *b:ale_lua_lua_format_options*
+ Type: |String|
+ Default: `''`
+
+ This variable can be set to pass additional options to lua-format.
+
+
+===============================================================================
luac *ale-lua-luac*
g:ale_lua_luac_executable *g:ale_lua_luac_executable*
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 7f2b632c..639e1833 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -285,6 +285,7 @@ Notes:
* LLVM
* `llc`
* Lua
+ * `lua-format`
* `luac`
* `luacheck`
* `luafmt`
diff --git a/doc/ale.txt b/doc/ale.txt
index df64f06a..53dd2ea2 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2840,6 +2840,7 @@ documented in additional help files.
llvm....................................|ale-llvm-options|
llc...................................|ale-llvm-llc|
lua.....................................|ale-lua-options|
+ lua-format............................|ale-lua-lua-format|
luac..................................|ale-lua-luac|
luacheck..............................|ale-lua-luacheck|
luafmt................................|ale-lua-luafmt|
diff --git a/supported-tools.md b/supported-tools.md
index 29ee9c5d..79d8e7df 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -294,6 +294,7 @@ formatting.
* LLVM
* [llc](https://llvm.org/docs/CommandGuide/llc.html)
* Lua
+ * [lua-format](https://github.com/Koihik/LuaFormatter)
* [luac](https://www.lua.org/manual/5.1/luac.html)
* [luacheck](https://github.com/mpeterv/luacheck)
* [luafmt](https://github.com/trixnz/lua-fmt)
diff --git a/test/fixers/test_lua_format_fixer_callback.vader b/test/fixers/test_lua_format_fixer_callback.vader
new file mode 100644
index 00000000..29cafde6
--- /dev/null
+++ b/test/fixers/test_lua_format_fixer_callback.vader
@@ -0,0 +1,35 @@
+Before:
+ Save g:ale_lua_lua_format_executable
+ Save g:ale_lua_lua_format_options
+
+ " Use an invalid global executable, so we don't match it.
+ let g:ale_lua_lua_format_executable = 'xxxinvalid'
+ let g:ale_lua_lua_format_options = ''
+
+ call ale#test#SetDirectory('/testplugin/test/fixers')
+
+After:
+ Restore
+
+ call ale#test#RestoreDirectory()
+
+Execute(The lua_format callback should return the correct default values):
+ call ale#test#SetFilename('../test-files/lua/testfile.lua')
+
+ AssertEqual
+ \ {
+ \ 'command': ale#Escape('xxxinvalid') . ' -i',
+ \ },
+ \ ale#fixers#lua_format#Fix(bufnr(''))
+
+Execute(The lua_format callback should include custom lua_format options):
+ let g:ale_lua_lua_format_options = "--no-chop-down-table"
+ call ale#test#SetFilename('../test-files/lua/testfile.lua')
+
+ AssertEqual
+ \ {
+ \ 'command': ale#Escape('xxxinvalid')
+ \ . ' ' . g:ale_lua_lua_format_options
+ \ . ' -i',
+ \ },
+ \ ale#fixers#lua_format#Fix(bufnr(''))