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

Fix cwd setting to use .stylua.toml if stylua.toml is not found #4892

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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.