summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Liebowitz <rliebz@gmail.com>2021-07-03 05:50:48 -0400
committerGitHub <noreply@github.com>2021-07-03 18:50:48 +0900
commit0d90cb64c6d14177f6915649243d272e1308dfaf (patch)
tree1fc1c1d831f966fb1134baad471e518f25b9adc7
parentb749ec702af29fb4d8a550c585704b3b351134d9 (diff)
downloadale-0d90cb64c6d14177f6915649243d272e1308dfaf.zip
Add stylua fixer for lua (#3789)
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/stylua.vim14
-rw-r--r--doc/ale-lua.txt20
-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_stylua_fixer_callback.vader19
7 files changed, 61 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 1cd5b6ef..5a138484 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -441,6 +441,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['lua'],
\ 'description': 'Fix Lua files with luafmt.',
\ },
+\ 'stylua': {
+\ 'function': 'ale#fixers#stylua#Fix',
+\ 'suggested_filetypes': ['lua'],
+\ 'description': 'Fix Lua files with stylua.',
+\ },
\ 'ormolu': {
\ 'function': 'ale#fixers#ormolu#Fix',
\ 'suggested_filetypes': ['haskell'],
diff --git a/autoload/ale/fixers/stylua.vim b/autoload/ale/fixers/stylua.vim
new file mode 100644
index 00000000..3521c935
--- /dev/null
+++ b/autoload/ale/fixers/stylua.vim
@@ -0,0 +1,14 @@
+" Author: Robert Liebowitz <rliebz@gmail.com>
+" Description: https://github.com/johnnymorganz/stylua
+
+call ale#Set('lua_stylua_executable', 'stylua')
+call ale#Set('lua_stylua_options', '')
+
+function! ale#fixers#stylua#Fix(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'lua_stylua_executable')
+ let l:options = ale#Var(a:buffer, 'lua_stylua_options')
+
+ return {
+ \ 'command': ale#Escape(l:executable) . ale#Pad(l:options) . ' -',
+ \}
+endfunction
diff --git a/doc/ale-lua.txt b/doc/ale-lua.txt
index 408f0c3c..db7c0924 100644
--- a/doc/ale-lua.txt
+++ b/doc/ale-lua.txt
@@ -46,5 +46,25 @@ g:ale_lua_luafmt_options *g:ale_lua_luafmt_options*
Default: `''`
This variable can be set to pass additional options to the luafmt fixer.
+
+
+===============================================================================
+stylua *ale-lua-stylua*
+
+g:ale_lua_stylua_executable *g:ale_lua_stylua_executable*
+ *b:ale_lua_stylua_executable*
+ Type: |String|
+ Default: `'stylua'`
+
+ This variable can be set to use a different executable for stylua.
+
+g:ale_lua_stylua_options *g:ale_lua_stylua_options*
+ *b:ale_lua_stylua_options*
+ Type: |String|
+ Default: `''`
+
+ This variable can be set to pass additional options to the stylua fixer.
+
+
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 4a901488..71fb64b8 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -288,6 +288,7 @@ Notes:
* `luac`
* `luacheck`
* `luafmt`
+ * `stylua`
* Mail
* `alex`!!
* `languagetool`!!
diff --git a/doc/ale.txt b/doc/ale.txt
index a126f360..6c6a363e 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2843,6 +2843,7 @@ documented in additional help files.
luac..................................|ale-lua-luac|
luacheck..............................|ale-lua-luacheck|
luafmt................................|ale-lua-luafmt|
+ stylua................................|ale-lua-stylua|
markdown................................|ale-markdown-options|
markdownlint..........................|ale-markdown-markdownlint|
mdl...................................|ale-markdown-mdl|
diff --git a/supported-tools.md b/supported-tools.md
index 7848d111..14c92dd9 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -297,6 +297,7 @@ formatting.
* [luac](https://www.lua.org/manual/5.1/luac.html)
* [luacheck](https://github.com/mpeterv/luacheck)
* [luafmt](https://github.com/trixnz/lua-fmt)
+ * [stylua](https://github.com/johnnymorganz/stylua)
* Mail
* [alex](https://github.com/wooorm/alex) :floppy_disk:
* [languagetool](https://languagetool.org/) :floppy_disk:
diff --git a/test/fixers/test_stylua_fixer_callback.vader b/test/fixers/test_stylua_fixer_callback.vader
new file mode 100644
index 00000000..8621c498
--- /dev/null
+++ b/test/fixers/test_stylua_fixer_callback.vader
@@ -0,0 +1,19 @@
+Before:
+ call ale#assert#SetUpFixerTest('lua', 'stylua')
+
+After:
+ call ale#assert#TearDownFixerTest()
+
+Execute(The default command should be correct):
+ AssertFixer {'command': ale#Escape('stylua') . ' -'}
+
+Execute(The stylua callback should include custom stylua options):
+ let g:ale_lua_stylua_executable = 'xxxinvalid'
+ let g:ale_lua_stylua_options = '--search-parent-directories'
+
+ AssertFixer
+ \ {
+ \ 'command': ale#Escape('xxxinvalid')
+ \ . ' ' . g:ale_lua_stylua_options
+ \ . ' -',
+ \ }