Add stylua fixer for lua (#3789)

This commit is contained in:
Robert Liebowitz 2021-07-03 05:50:48 -04:00 committed by GitHub
parent b749ec702a
commit 0d90cb64c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 0 deletions

View File

@ -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'],

View File

@ -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

View File

@ -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:

View File

@ -288,6 +288,7 @@ Notes:
* `luac`
* `luacheck`
* `luafmt`
* `stylua`
* Mail
* `alex`!!
* `languagetool`!!

View File

@ -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|

View File

@ -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:

View File

@ -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
\ . ' -',
\ }