From 6db58b33795430a6165f27c7f796c420c0e098e4 Mon Sep 17 00:00:00 2001 From: Kevin Van Leer Date: Sun, 7 Apr 2024 03:34:02 -0500 Subject: [PATCH] Added fix subcommand options (#4746) 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. --- autoload/ale/fixers/php_cs_fixer.vim | 4 +++- test/fixers/test_php_cs_fixer.vader | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/autoload/ale/fixers/php_cs_fixer.vim b/autoload/ale/fixers/php_cs_fixer.vim index c8f9c7b0..96c6445c 100644 --- a/autoload/ale/fixers/php_cs_fixer.vim +++ b/autoload/ale/fixers/php_cs_fixer.vim @@ -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', [ @@ -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 diff --git a/test/fixers/test_php_cs_fixer.vader b/test/fixers/test_php_cs_fixer.vader index eb4d78f8..9ae98208 100644 --- a/test/fixers/test_php_cs_fixer.vader +++ b/test/fixers/test_php_cs_fixer.vader @@ -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') @@ -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(''))