diff options
author | Eric Stern <github@ericstern.com> | 2017-06-21 13:35:40 -0700 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2017-06-21 21:35:40 +0100 |
commit | ab534c2995dabfb8adcdc62d0ac66ed1b1110f4c (patch) | |
tree | 29418f9a0ad95d375ccaaf239c75f24850e28292 /ale_linters/php | |
parent | d2806fad600e361e5b419e528c0e999bb4ac9b7f (diff) | |
download | ale-ab534c2995dabfb8adcdc62d0ac66ed1b1110f4c.zip |
Support project's local phpcs installation (#666)
* Use locally-installed PHPCS if available
* Add author
* Add configuration options
* Escape executable
* Add tests
Diffstat (limited to 'ale_linters/php')
-rw-r--r-- | ale_linters/php/phpcs.vim | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/ale_linters/php/phpcs.vim b/ale_linters/php/phpcs.vim index 94c887c4..a8eae4e6 100644 --- a/ale_linters/php/phpcs.vim +++ b/ale_linters/php/phpcs.vim @@ -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 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 + let l:executable = ale_linters#php#phpcs#GetExecutable(a:buffer) + let l:standard = ale#Var(a:buffer, 'php_phpcs_standard') let l:standard_option = !empty(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 function! ale_linters#php#phpcs#Handle(buffer, lines) abort @@ -36,7 +49,7 @@ endfunction call ale#linter#Define('php', { \ 'name': 'phpcs', -\ 'executable': 'phpcs', +\ 'executable_callback': 'ale_linters#php#phpcs#GetExecutable', \ 'command_callback': 'ale_linters#php#phpcs#GetCommand', \ 'callback': 'ale_linters#php#phpcs#Handle', \}) |