diff --git a/autoload/ale/fixers/stylua.vim b/autoload/ale/fixers/stylua.vim index 925e960cf3..6c3ba0549a 100644 --- a/autoload/ale/fixers/stylua.vim +++ b/autoload/ale/fixers/stylua.vim @@ -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 diff --git a/test/fixers/test_stylua_fixer_callback.vader b/test/fixers/test_stylua_fixer_callback.vader index 07d085128f..975721523a 100644 --- a/test/fixers/test_stylua_fixer_callback.vader +++ b/test/fixers/test_stylua_fixer_callback.vader @@ -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 -', + \ } diff --git a/test/test-files/stylua/stylua_config_dir/stylua.toml b/test/test-files/stylua/stylua_config_dir/stylua.toml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test-files/stylua/stylua_dot_config_dir/.stylua.toml b/test/test-files/stylua/stylua_dot_config_dir/.stylua.toml new file mode 100644 index 0000000000..e69de29bb2