2018-10-19 19:51:16 +00:00
|
|
|
" Author: Matt Brown <https://github.com/muglug>
|
2018-09-27 15:48:47 +00:00
|
|
|
" Description: plugin for Psalm, static analyzer for PHP
|
|
|
|
|
2020-08-29 15:31:47 +00:00
|
|
|
call ale#Set('php_psalm_executable', 'psalm')
|
|
|
|
call ale#Set('php_psalm_options', '')
|
|
|
|
call ale#Set('php_psalm_use_global', get(g:, 'ale_use_global_executables', 0))
|
2018-09-27 15:48:47 +00:00
|
|
|
|
2018-10-19 19:51:16 +00:00
|
|
|
function! ale_linters#php#psalm#GetProjectRoot(buffer) abort
|
2021-11-15 12:17:18 +00:00
|
|
|
let l:composer_path = ale#path#FindNearestFile(a:buffer, 'composer.json')
|
|
|
|
|
|
|
|
if (!empty(l:composer_path))
|
|
|
|
return fnamemodify(l:composer_path, ':h')
|
|
|
|
endif
|
|
|
|
|
2018-10-19 19:51:16 +00:00
|
|
|
let l:git_path = ale#path#FindNearestDirectory(a:buffer, '.git')
|
2018-09-27 15:48:47 +00:00
|
|
|
|
2018-10-19 19:51:16 +00:00
|
|
|
return !empty(l:git_path) ? fnamemodify(l:git_path, ':h:h') : ''
|
2018-09-27 15:48:47 +00:00
|
|
|
endfunction
|
|
|
|
|
2019-07-25 21:01:53 +00:00
|
|
|
function! ale_linters#php#psalm#GetCommand(buffer) abort
|
2020-08-29 15:31:47 +00:00
|
|
|
return '%e --language-server' . ale#Pad(ale#Var(a:buffer, 'php_psalm_options'))
|
2019-07-25 21:01:53 +00:00
|
|
|
endfunction
|
|
|
|
|
2018-09-27 15:48:47 +00:00
|
|
|
call ale#linter#Define('php', {
|
|
|
|
\ 'name': 'psalm',
|
2018-10-19 19:51:16 +00:00
|
|
|
\ 'lsp': 'stdio',
|
2021-05-26 21:43:30 +00:00
|
|
|
\ 'executable': {b -> ale#path#FindExecutable(b, 'php_psalm', [
|
2019-07-25 21:00:49 +00:00
|
|
|
\ 'vendor/bin/psalm',
|
2019-02-22 18:05:04 +00:00
|
|
|
\ ])},
|
2019-07-25 21:01:53 +00:00
|
|
|
\ 'command': function('ale_linters#php#psalm#GetCommand'),
|
2019-02-22 18:05:04 +00:00
|
|
|
\ 'project_root': function('ale_linters#php#psalm#GetProjectRoot'),
|
2018-09-27 15:48:47 +00:00
|
|
|
\})
|