Skip to content

Commit

Permalink
Fix cwd setting to use .stylua.toml if stylua.toml is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
ponko2 committed Jan 13, 2025
1 parent 6c337ad commit 17c3e9c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions autoload/ale/fixers/stylua.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions test/fixers/test_stylua_fixer_callback.vader
Original file line number Diff line number Diff line change
Expand Up @@ -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 -',
\ }
Empty file.
Empty file.

0 comments on commit 17c3e9c

Please sign in to comment.