commit
9bdd5771ef
@ -1,28 +1,21 @@
|
|||||||
" Author: richard marmorstein <https://github.com/twitchard>
|
" Author: Matt Brown <https://github.com/muglug>
|
||||||
" Description: plugin for Psalm, static analyzer for PHP
|
" Description: plugin for Psalm, static analyzer for PHP
|
||||||
|
|
||||||
call ale#Set('php_psalm_executable', 'psalm')
|
call ale#Set('psalm_langserver_executable', 'psalm-language-server')
|
||||||
|
call ale#Set('psalm_langserver_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||||
|
|
||||||
function! ale_linters#php#psalm#Handle(buffer, lines) abort
|
function! ale_linters#php#psalm#GetProjectRoot(buffer) abort
|
||||||
" Matches patterns like the following:
|
let l:git_path = ale#path#FindNearestDirectory(a:buffer, '.git')
|
||||||
let l:pattern = '^.*:\(\d\+\):\(\d\+\):\(\w\+\) - \(.*\)$'
|
|
||||||
let l:output = []
|
|
||||||
|
|
||||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
return !empty(l:git_path) ? fnamemodify(l:git_path, ':h:h') : ''
|
||||||
call add(l:output, {
|
|
||||||
\ 'lnum': l:match[1] + 0,
|
|
||||||
\ 'text': l:match[4],
|
|
||||||
\ 'type': l:match[3][:0] is# 'e' ? 'E' : 'W',
|
|
||||||
\})
|
|
||||||
endfor
|
|
||||||
|
|
||||||
return l:output
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call ale#linter#Define('php', {
|
call ale#linter#Define('php', {
|
||||||
\ 'name': 'psalm',
|
\ 'name': 'psalm',
|
||||||
\ 'command': '%e --diff --output-format=emacs %s',
|
\ 'lsp': 'stdio',
|
||||||
\ 'executable_callback': ale#VarFunc('php_psalm_executable'),
|
\ 'executable_callback': ale#node#FindExecutableFunc('psalm_langserver', [
|
||||||
\ 'callback': 'ale_linters#php#psalm#Handle',
|
\ 'vendor/bin/psalm-language-server',
|
||||||
\ 'lint_file': 1,
|
\ ]),
|
||||||
|
\ 'command': '%e',
|
||||||
|
\ 'project_root_callback': 'ale_linters#php#psalm#GetProjectRoot',
|
||||||
\})
|
\})
|
||||||
|
0
test/command_callback/psalm-project/vendor/bin/psalm-language-server
vendored
Executable file
0
test/command_callback/psalm-project/vendor/bin/psalm-language-server
vendored
Executable file
@ -2,11 +2,28 @@ Before:
|
|||||||
call ale#assert#SetUpLinterTest('php', 'psalm')
|
call ale#assert#SetUpLinterTest('php', 'psalm')
|
||||||
|
|
||||||
After:
|
After:
|
||||||
|
if isdirectory(g:dir . '/.git')
|
||||||
|
call delete(g:dir . '/.git', 'd')
|
||||||
|
endif
|
||||||
|
|
||||||
call ale#assert#TearDownLinterTest()
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
Execute(Custom executables should be used for the executable and command):
|
Execute(The default executable path should be correct):
|
||||||
let g:ale_php_psalm_executable = 'psalm_test'
|
AssertLinter 'psalm-language-server',
|
||||||
|
\ ale#Escape('psalm-language-server')
|
||||||
|
|
||||||
AssertLinter 'psalm_test',
|
Execute(Vendor executables should be detected):
|
||||||
\ ale#Escape('psalm_test') . ' --diff --output-format=emacs %s'
|
call ale#test#SetFilename('psalm-project/test.php')
|
||||||
|
|
||||||
|
AssertLinter
|
||||||
|
\ ale#path#Simplify(g:dir . '/psalm-project/vendor/bin/psalm-language-server'),
|
||||||
|
\ ale#Escape(ale#path#Simplify(
|
||||||
|
\ g:dir
|
||||||
|
\ . '/psalm-project/vendor/bin/psalm-language-server'
|
||||||
|
\ ))
|
||||||
|
|
||||||
|
Execute(The project path should be correct for .git directories):
|
||||||
|
call ale#test#SetFilename('psalm-project/test.php')
|
||||||
|
call mkdir(g:dir . '/.git')
|
||||||
|
|
||||||
|
AssertLSPProject g:dir
|
@ -1,24 +0,0 @@
|
|||||||
Before:
|
|
||||||
runtime ale_linters/php/psalm.vim
|
|
||||||
|
|
||||||
After:
|
|
||||||
call ale#linter#Reset()
|
|
||||||
|
|
||||||
Execute(The php static analyzer handler should parse errors from psalm):
|
|
||||||
AssertEqual
|
|
||||||
\ [
|
|
||||||
\ {
|
|
||||||
\ 'lnum': 1,
|
|
||||||
\ 'type': 'W',
|
|
||||||
\ 'text': 'somewarning',
|
|
||||||
\ },
|
|
||||||
\ {
|
|
||||||
\ 'lnum': 11,
|
|
||||||
\ 'type': 'E',
|
|
||||||
\ 'text': 'someerror',
|
|
||||||
\ },
|
|
||||||
\ ],
|
|
||||||
\ ale_linters#php#psalm#Handle(347, [
|
|
||||||
\ "/file:1:3:warning - somewarning",
|
|
||||||
\ "/file:11:33:error - someerror",
|
|
||||||
\ ])
|
|
Loading…
Reference in New Issue
Block a user