Skip to content

Commit

Permalink
Added fix subcommand options (dense-analysis#4746)
Browse files Browse the repository at this point in the history
php-cs-fixer command line options are ordered. Options that appear after the
main command are applied to the main command. Options that appear after the
subcommands are applied to the subcommands. This change enables a user to
specific fix options (like --config). This change also sets the plugin to
find the the configuraiton file in the current project tree. This matches
the default behavior of other linters like eslint.
  • Loading branch information
kevinvanleer authored Apr 7, 2024
1 parent b6b9612 commit 6db58b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion autoload/ale/fixers/php_cs_fixer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
call ale#Set('php_cs_fixer_executable', 'php-cs-fixer')
call ale#Set('php_cs_fixer_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('php_cs_fixer_options', '')
call ale#Set('php_cs_fixer_fix_options', '')

function! ale#fixers#php_cs_fixer#GetExecutable(buffer) abort
return ale#path#FindExecutable(a:buffer, 'php_cs_fixer', [
Expand All @@ -18,7 +19,8 @@ function! ale#fixers#php_cs_fixer#Fix(buffer) abort
return {
\ 'command': ale#Escape(l:executable)
\ . ' ' . ale#Var(a:buffer, 'php_cs_fixer_options')
\ . ' fix %t',
\ . ' fix ' . ale#Var(a:buffer, 'php_cs_fixer_fix_options')
\ . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction
10 changes: 7 additions & 3 deletions test/fixers/test_php_cs_fixer.vader
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Before:
Save g:ale_php_cs_fixer_executable
Save g:ale_php_cs_fixer_options
Save g:ale_php_cs_fixer_fix_options
let g:ale_php_cs_fixer_executable = 'php-cs-fixer'
let g:ale_php_cs_fixer_options = ''
let g:ale_php_cs_fixer_fix_options = ''

call ale#test#SetDirectory('/testplugin/test/fixers')

Expand Down Expand Up @@ -45,18 +47,20 @@ Execute(The php-cs-fixer callback should return the correct default values):
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('php-cs-fixer')
\ . ' ' . g:ale_php_cs_fixer_options
\ . ' fix %t'
\ . ' fix ' . g:ale_php_cs_fixer_fix_options
\ . ' %t'
\ },
\ ale#fixers#php_cs_fixer#Fix(bufnr(''))

Execute(The php-cs-fixer callback should include custom php-cs-fixer options):
let g:ale_php_cs_fixer_options = '--config="$HOME/.php_cs"'
let g:ale_php_cs_fixer_options = '-nq'
let g:ale_php_cs_fixer_fix_options = '--config="$HOME/.php_cs"'
call ale#test#SetFilename('../test-files/php/project-without-php-cs-fixer/test.php')

AssertEqual
\ {
\ 'command': ale#Escape(g:ale_php_cs_fixer_executable)
\ . ' --config="$HOME/.php_cs" fix %t',
\ . ' -nq fix --config="$HOME/.php_cs" %t',
\ 'read_temporary_file': 1,
\ },
\ ale#fixers#php_cs_fixer#Fix(bufnr(''))

0 comments on commit 6db58b3

Please sign in to comment.