mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 20:54:26 +08:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(''))
|
||||
|
||||
Reference in New Issue
Block a user