Support project's local phpcs installation (#666)
* Use locally-installed PHPCS if available * Add author * Add configuration options * Escape executable * Add tests
This commit is contained in:
parent
d2806fad60
commit
ab534c2995
@ -1,15 +1,28 @@
|
|||||||
" Author: jwilliams108 <https://github.com/jwilliams108>
|
" Author: jwilliams108 <https://github.com/jwilliams108>, Eric Stern <https://github.com/firehed>
|
||||||
" Description: phpcs for PHP files
|
" Description: phpcs for PHP files
|
||||||
|
|
||||||
let g:ale_php_phpcs_standard = get(g:, 'ale_php_phpcs_standard', '')
|
let g:ale_php_phpcs_standard = get(g:, 'ale_php_phpcs_standard', '')
|
||||||
|
|
||||||
|
call ale#Set('php_phpcs_executable', 'phpcs')
|
||||||
|
call ale#Set('php_phpcs_use_global', 0)
|
||||||
|
|
||||||
|
function! ale_linters#php#phpcs#GetExecutable(buffer) abort
|
||||||
|
return ale#node#FindExecutable(a:buffer, 'php_phpcs', [
|
||||||
|
\ 'vendor/bin/phpcs',
|
||||||
|
\ 'phpcs'
|
||||||
|
\])
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#php#phpcs#GetCommand(buffer) abort
|
function! ale_linters#php#phpcs#GetCommand(buffer) abort
|
||||||
|
let l:executable = ale_linters#php#phpcs#GetExecutable(a:buffer)
|
||||||
|
|
||||||
let l:standard = ale#Var(a:buffer, 'php_phpcs_standard')
|
let l:standard = ale#Var(a:buffer, 'php_phpcs_standard')
|
||||||
let l:standard_option = !empty(l:standard)
|
let l:standard_option = !empty(l:standard)
|
||||||
\ ? '--standard=' . l:standard
|
\ ? '--standard=' . l:standard
|
||||||
\ : ''
|
\ : ''
|
||||||
|
|
||||||
return 'phpcs -s --report=emacs --stdin-path=%s ' . l:standard_option
|
return ale#Escape(l:executable)
|
||||||
|
\ . ' -s --report=emacs --stdin-path=%s ' . l:standard_option
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#php#phpcs#Handle(buffer, lines) abort
|
function! ale_linters#php#phpcs#Handle(buffer, lines) abort
|
||||||
@ -36,7 +49,7 @@ endfunction
|
|||||||
|
|
||||||
call ale#linter#Define('php', {
|
call ale#linter#Define('php', {
|
||||||
\ 'name': 'phpcs',
|
\ 'name': 'phpcs',
|
||||||
\ 'executable': 'phpcs',
|
\ 'executable_callback': 'ale_linters#php#phpcs#GetExecutable',
|
||||||
\ 'command_callback': 'ale_linters#php#phpcs#GetCommand',
|
\ 'command_callback': 'ale_linters#php#phpcs#GetCommand',
|
||||||
\ 'callback': 'ale_linters#php#phpcs#Handle',
|
\ 'callback': 'ale_linters#php#phpcs#Handle',
|
||||||
\})
|
\})
|
||||||
|
0
test/phpcs-test-files/project-with-phpcs/vendor/bin/phpcs
vendored
Normal file
0
test/phpcs-test-files/project-with-phpcs/vendor/bin/phpcs
vendored
Normal file
45
test/test_phpcs_executable_detection.vader
Normal file
45
test/test_phpcs_executable_detection.vader
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
Before:
|
||||||
|
let g:ale_php_phpcs_executable = 'phpcs_test'
|
||||||
|
|
||||||
|
silent! cd /testplugin/test
|
||||||
|
let g:dir = getcwd()
|
||||||
|
|
||||||
|
runtime ale_linters/php/phpcs.vim
|
||||||
|
|
||||||
|
After:
|
||||||
|
let g:ale_php_phpcs_executable = 'phpcs'
|
||||||
|
let g:ale_php_phpcs_use_global = 0
|
||||||
|
|
||||||
|
silent execute 'cd ' . g:dir
|
||||||
|
unlet! g:dir
|
||||||
|
|
||||||
|
call ale#linter#Reset()
|
||||||
|
|
||||||
|
Execute(project with phpcs should use local by default):
|
||||||
|
silent noautocmd new phpcs-test-files/project-with-phpcs/vendor/bin/phpcs
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ g:dir . '/phpcs-test-files/project-with-phpcs/vendor/bin/phpcs',
|
||||||
|
\ ale_linters#php#phpcs#GetExecutable(bufnr(''))
|
||||||
|
|
||||||
|
:q
|
||||||
|
|
||||||
|
Execute(use-global should override local detection):
|
||||||
|
let g:ale_php_phpcs_use_global = 1
|
||||||
|
|
||||||
|
silent noautocmd new phpcs-test-files/project-with-phpcs/vendor/bin/phpcs
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ 'phpcs_test',
|
||||||
|
\ ale_linters#php#phpcs#GetExecutable(bufnr(''))
|
||||||
|
|
||||||
|
:q
|
||||||
|
|
||||||
|
Execute(project without phpcs should use global):
|
||||||
|
silent noautocmd new phpcs-test-files/project-without-phpcs/vendor/bin/phpcs
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ 'phpcs_test',
|
||||||
|
\ ale_linters#php#phpcs#GetExecutable(bufnr(''))
|
||||||
|
|
||||||
|
:q
|
Loading…
Reference in New Issue
Block a user