Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for lua-format fixer. #3804

Merged
merged 1 commit into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
16 changes: 16 additions & 0 deletions autoload/ale/fixers/lua_format.vim
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions doc/ale-lua.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,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*

Expand Down
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ Notes:
* LLVM
* `llc`
* Lua
* `lua-format`
* `luac`
* `luacheck`
* `luafmt`
Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 35 additions & 0 deletions test/fixers/test_lua_format_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -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(''))