Fix cwd setting to use .stylua.toml if stylua.toml is not found (#4892)
Some checks failed
CI / build_image (push) Has been cancelled
CI / test_ale (--linters-only) (push) Has been cancelled
CI / test_ale (--neovim-06-only) (push) Has been cancelled
CI / test_ale (--neovim-08-only) (push) Has been cancelled
CI / test_ale (--vim-80-only) (push) Has been cancelled
CI / test_ale (--vim-90-only) (push) Has been cancelled

This commit is contained in:
Takahito Nakano
2025-02-07 18:19:05 +09:00
committed by GitHub
parent 62af9f2650
commit e5d6d94f71
4 changed files with 22 additions and 2 deletions

View File

@@ -8,10 +8,12 @@ function! ale#fixers#stylua#GetCwd(buffer) abort
for l:possible_configfile in ['stylua.toml', '.stylua.toml']
let l:config = ale#path#FindNearestFile(a:buffer, l:possible_configfile)
return !empty(l:config) ? fnamemodify(l:config, ':h') : '%s:h'
if !empty(l:config)
return fnamemodify(l:config, ':h')
endif
endfor
return ''
return '%s:h'
endfunction
function! ale#fixers#stylua#Fix(buffer) abort

View File

@@ -18,3 +18,21 @@ Execute(The stylua callback should include custom stylua options):
\ . ' ' . g:ale_lua_stylua_options
\ . ' --stdin-filepath %s -',
\ }
Execute(stylua should detect stylua.toml):
call ale#test#SetFilename('../test-files/stylua/stylua_config_dir/subdir/test.lua')
AssertFixer
\ {
\ 'cwd': ale#path#Simplify(g:dir . '/../test-files/stylua/stylua_config_dir'),
\ 'command': ale#Escape('stylua') . ' --stdin-filepath %s -',
\ }
Execute(stylua should detect .stylua.toml):
call ale#test#SetFilename('../test-files/stylua/stylua_dot_config_dir/subdir/test.lua')
AssertFixer
\ {
\ 'cwd': ale#path#Simplify(g:dir . '/../test-files/stylua/stylua_dot_config_dir'),
\ 'command': ale#Escape('stylua') . ' --stdin-filepath %s -',
\ }