mirror of
https://github.com/dense-analysis/ale
synced 2025-03-08 22:27:42 +00:00
Add stylua fixer for lua (#3789)
This commit is contained in:
parent
b749ec702a
commit
0d90cb64c6
@ -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'],
|
||||
|
14
autoload/ale/fixers/stylua.vim
Normal file
14
autoload/ale/fixers/stylua.vim
Normal 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
|
@ -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:
|
||||
|
@ -288,6 +288,7 @@ Notes:
|
||||
* `luac`
|
||||
* `luacheck`
|
||||
* `luafmt`
|
||||
* `stylua`
|
||||
* Mail
|
||||
* `alex`!!
|
||||
* `languagetool`!!
|
||||
|
@ -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|
|
||||
|
@ -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:
|
||||
|
19
test/fixers/test_stylua_fixer_callback.vader
Normal file
19
test/fixers/test_stylua_fixer_callback.vader
Normal 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
|
||||
\ . ' -',
|
||||
\ }
|
Loading…
Reference in New Issue
Block a user