Add luafmt fixer (#3289)
This commit is contained in:
parent
8e28de142a
commit
e5d16caebe
8 changed files with 72 additions and 0 deletions
|
@ -375,6 +375,11 @@ let s:default_registry = {
|
|||
\ 'suggested_filetypes': ['html', 'htmldjango'],
|
||||
\ 'description': 'Fix HTML files with html-beautify.',
|
||||
\ },
|
||||
\ 'luafmt': {
|
||||
\ 'function': 'ale#fixers#luafmt#Fix',
|
||||
\ 'suggested_filetypes': ['lua'],
|
||||
\ 'description': 'Fix Lua files with luafmt.',
|
||||
\ },
|
||||
\ 'dhall': {
|
||||
\ 'function': 'ale#fixers#dhall#Fix',
|
||||
\ 'suggested_filetypes': ['dhall'],
|
||||
|
|
13
autoload/ale/fixers/luafmt.vim
Normal file
13
autoload/ale/fixers/luafmt.vim
Normal file
|
@ -0,0 +1,13 @@
|
|||
call ale#Set('lua_luafmt_executable', 'luafmt')
|
||||
call ale#Set('lua_luafmt_options', '')
|
||||
|
||||
function! ale#fixers#luafmt#Fix(buffer) abort
|
||||
let l:executable = ale#Var(a:buffer, 'lua_luafmt_executable')
|
||||
let l:options = ale#Var(a:buffer, 'lua_luafmt_options')
|
||||
|
||||
return {
|
||||
\ 'command': ale#Escape(l:executable)
|
||||
\ . (empty(l:options) ? '' : ' ' . l:options)
|
||||
\ . ' --stdin',
|
||||
\}
|
||||
endfunction
|
|
@ -30,5 +30,21 @@ g:ale_lua_luacheck_options *g:ale_lua_luacheck_options*
|
|||
This variable can be set to pass additional options to luacheck.
|
||||
|
||||
|
||||
===============================================================================
|
||||
luafmt *ale-lua-luafmt*
|
||||
|
||||
g:ale_lua_luafmt_executable *g:ale_lua_luafmt_executable*
|
||||
*b:ale_lua_luafmt_executable*
|
||||
Type: |String|
|
||||
Default: `'luafmt'`
|
||||
|
||||
This variable can be set to use a different executable for luafmt.
|
||||
|
||||
g:ale_lua_luafmt_options *g:ale_lua_luafmt_options*
|
||||
*b:ale_lua_luafmt_options*
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
This variable can be set to pass additional options to the luafmt fixer.
|
||||
===============================================================================
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||
|
|
|
@ -266,6 +266,7 @@ Notes:
|
|||
* Lua
|
||||
* `luac`
|
||||
* `luacheck`
|
||||
* `luafmt`
|
||||
* Mail
|
||||
* `alex`!!
|
||||
* `languagetool`!!
|
||||
|
|
|
@ -2744,6 +2744,7 @@ documented in additional help files.
|
|||
lua.....................................|ale-lua-options|
|
||||
luac..................................|ale-lua-luac|
|
||||
luacheck..............................|ale-lua-luacheck|
|
||||
luafmt................................|ale-lua-luafmt|
|
||||
markdown................................|ale-markdown-options|
|
||||
markdownlint..........................|ale-markdown-markdownlint|
|
||||
mdl...................................|ale-markdown-mdl|
|
||||
|
|
|
@ -275,6 +275,7 @@ formatting.
|
|||
* Lua
|
||||
* [luac](https://www.lua.org/manual/5.1/luac.html)
|
||||
* [luacheck](https://github.com/mpeterv/luacheck)
|
||||
* [luafmt](https://github.com/trixnz/lua-fmt)
|
||||
* Mail
|
||||
* [alex](https://github.com/wooorm/alex) :floppy_disk:
|
||||
* [languagetool](https://languagetool.org/) :floppy_disk:
|
||||
|
|
35
test/fixers/test_luafmt_fixer_callback.vader
Normal file
35
test/fixers/test_luafmt_fixer_callback.vader
Normal file
|
@ -0,0 +1,35 @@
|
|||
Before:
|
||||
Save g:ale_lua_luafmt_executable
|
||||
Save g:ale_lua_luafmt_options
|
||||
|
||||
" Use an invalid global executable, so we don't match it.
|
||||
let g:ale_lua_luafmt_executable = 'xxxinvalid'
|
||||
let g:ale_lua_luafmt_options = ''
|
||||
|
||||
call ale#test#SetDirectory('/testplugin/test/fixers')
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
call ale#test#RestoreDirectory()
|
||||
|
||||
Execute(The luafmt callback should return the correct default values):
|
||||
call ale#test#SetFilename('../lua_files/testfile.lua')
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': ale#Escape('xxxinvalid') . ' --stdin',
|
||||
\ },
|
||||
\ ale#fixers#luafmt#Fix(bufnr(''))
|
||||
|
||||
Execute(The luafmt callback should include custom luafmt options):
|
||||
let g:ale_lua_luafmt_options = "--skip-children"
|
||||
call ale#test#SetFilename('../lua_files/testfile.lua')
|
||||
|
||||
AssertEqual
|
||||
\ {
|
||||
\ 'command': ale#Escape('xxxinvalid')
|
||||
\ . ' ' . g:ale_lua_luafmt_options
|
||||
\ . ' --stdin',
|
||||
\ },
|
||||
\ ale#fixers#luafmt#Fix(bufnr(''))
|
0
test/lua_files/testfile.lua
Normal file
0
test/lua_files/testfile.lua
Normal file
Reference in a new issue