From 217284360d35711b751859ed27a7a3c3da300e85 Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 2 Aug 2018 23:44:12 +0100 Subject: Simplify the code for most linters and tests with closures --- ale_linters/php/langserver.vim | 16 ++++------------ ale_linters/php/phpcs.vim | 17 +++++------------ ale_linters/php/phpmd.vim | 13 +++---------- ale_linters/php/phpstan.vim | 11 ++--------- 4 files changed, 14 insertions(+), 43 deletions(-) (limited to 'ale_linters/php') diff --git a/ale_linters/php/langserver.vim b/ale_linters/php/langserver.vim index 38b42df9..ca91db4c 100644 --- a/ale_linters/php/langserver.vim +++ b/ale_linters/php/langserver.vim @@ -4,16 +4,6 @@ call ale#Set('php_langserver_executable', 'php-language-server.php') call ale#Set('php_langserver_use_global', get(g:, 'ale_use_global_executables', 0)) -function! ale_linters#php#langserver#GetExecutable(buffer) abort - return ale#node#FindExecutable(a:buffer, 'php_langserver', [ - \ 'vendor/bin/php-language-server.php', - \]) -endfunction - -function! ale_linters#php#langserver#GetCommand(buffer) abort - return 'php ' . ale#Escape(ale_linters#php#langserver#GetExecutable(a:buffer)) -endfunction - function! ale_linters#php#langserver#GetProjectRoot(buffer) abort let l:git_path = ale#path#FindNearestDirectory(a:buffer, '.git') @@ -23,7 +13,9 @@ endfunction call ale#linter#Define('php', { \ 'name': 'langserver', \ 'lsp': 'stdio', -\ 'executable_callback': 'ale_linters#php#langserver#GetExecutable', -\ 'command_callback': 'ale_linters#php#langserver#GetCommand', +\ 'executable_callback': ale#node#FindExecutableFunc('php_langserver', [ +\ 'vendor/bin/php-language-server.php', +\ ]), +\ 'command': 'php %e', \ 'project_root_callback': 'ale_linters#php#langserver#GetProjectRoot', \}) diff --git a/ale_linters/php/phpcs.vim b/ale_linters/php/phpcs.vim index faf8ad55..25e53714 100644 --- a/ale_linters/php/phpcs.vim +++ b/ale_linters/php/phpcs.vim @@ -6,23 +6,13 @@ 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', get(g:, 'ale_use_global_executables', 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 ale#Escape(l:executable) - \ . ' -s --report=emacs --stdin-path=%s ' . l:standard_option + return '%e -s --report=emacs --stdin-path=%s' . ale#Pad(l:standard_option) endfunction function! ale_linters#php#phpcs#Handle(buffer, lines) abort @@ -50,7 +40,10 @@ endfunction call ale#linter#Define('php', { \ 'name': 'phpcs', -\ 'executable_callback': 'ale_linters#php#phpcs#GetExecutable', +\ 'executable_callback': ale#node#FindExecutableFunc('php_phpcs', [ +\ 'vendor/bin/phpcs', +\ 'phpcs' +\ ]), \ 'command_callback': 'ale_linters#php#phpcs#GetCommand', \ 'callback': 'ale_linters#php#phpcs#Handle', \}) diff --git a/ale_linters/php/phpmd.vim b/ale_linters/php/phpmd.vim index e9450752..65f1cc3c 100644 --- a/ale_linters/php/phpmd.vim +++ b/ale_linters/php/phpmd.vim @@ -6,16 +6,9 @@ let g:ale_php_phpmd_executable = get(g:, 'ale_php_phpmd_executable', 'phpmd') " Set to change the ruleset let g:ale_php_phpmd_ruleset = get(g:, 'ale_php_phpmd_ruleset', 'cleancode,codesize,controversial,design,naming,unusedcode') -function! ale_linters#php#phpmd#GetExecutable(buffer) abort - return ale#Var(a:buffer, 'php_phpmd_executable') -endfunction - function! ale_linters#php#phpmd#GetCommand(buffer) abort - let l:executable = ale_linters#php#phpmd#GetExecutable(a:buffer) - - return ale#Escape(l:executable) - \ . ' %s text ' - \ . ale#Var(a:buffer, 'php_phpmd_ruleset') + return '%e %s text' + \ . ale#Pad(ale#Var(a:buffer, 'php_phpmd_ruleset')) \ . ' --ignore-violations-on-exit %t' endfunction @@ -39,7 +32,7 @@ endfunction call ale#linter#Define('php', { \ 'name': 'phpmd', -\ 'executable_callback': 'ale_linters#php#phpmd#GetExecutable', +\ 'executable_callback': ale#VarFunc('php_phpmd_executable'), \ 'command_callback': 'ale_linters#php#phpmd#GetCommand', \ 'callback': 'ale_linters#php#phpmd#Handle', \}) diff --git a/ale_linters/php/phpstan.vim b/ale_linters/php/phpstan.vim index 24762086..b3875216 100644 --- a/ale_linters/php/phpstan.vim +++ b/ale_linters/php/phpstan.vim @@ -6,20 +6,13 @@ let g:ale_php_phpstan_executable = get(g:, 'ale_php_phpstan_executable', 'phpsta let g:ale_php_phpstan_level = get(g:, 'ale_php_phpstan_level', '4') let g:ale_php_phpstan_configuration = get(g:, 'ale_php_phpstan_configuration', '') -function! ale_linters#php#phpstan#GetExecutable(buffer) abort - return ale#Var(a:buffer, 'php_phpstan_executable') -endfunction - function! ale_linters#php#phpstan#GetCommand(buffer) abort - let l:executable = ale_linters#php#phpstan#GetExecutable(a:buffer) - let l:configuration = ale#Var(a:buffer, 'php_phpstan_configuration') let l:configuration_option = !empty(l:configuration) \ ? ' -c ' . l:configuration \ : '' - return ale#Escape(l:executable) - \ . ' analyze -l' + return '%e analyze -l' \ . ale#Var(a:buffer, 'php_phpstan_level') \ . ' --errorFormat raw' \ . l:configuration_option @@ -47,7 +40,7 @@ endfunction call ale#linter#Define('php', { \ 'name': 'phpstan', -\ 'executable_callback': 'ale_linters#php#phpstan#GetExecutable', +\ 'executable_callback': ale#VarFunc('php_phpstan_executable'), \ 'command_callback': 'ale_linters#php#phpstan#GetCommand', \ 'callback': 'ale_linters#php#phpstan#Handle', \}) -- cgit v1.2.3