2017-11-05 13:53:12 -05:00
|
|
|
" Author: medains <https://github.com/medains>, David Sierra <https://github.com/davidsierradz>
|
2017-02-01 11:09:33 -05:00
|
|
|
" Description: phpmd for PHP files
|
|
|
|
|
2017-11-05 13:53:12 -05:00
|
|
|
let g:ale_php_phpmd_executable = get(g:, 'ale_php_phpmd_executable', 'phpmd')
|
|
|
|
|
2017-02-01 11:09:33 -05:00
|
|
|
" Set to change the ruleset
|
|
|
|
let g:ale_php_phpmd_ruleset = get(g:, 'ale_php_phpmd_ruleset', 'cleancode,codesize,controversial,design,naming,unusedcode')
|
|
|
|
|
2017-11-05 13:53:12 -05:00
|
|
|
function! ale_linters#php#phpmd#GetExecutable(buffer) abort
|
|
|
|
return ale#Var(a:buffer, 'php_phpmd_executable')
|
|
|
|
endfunction
|
|
|
|
|
2017-04-15 08:35:54 -04:00
|
|
|
function! ale_linters#php#phpmd#GetCommand(buffer) abort
|
2017-11-05 13:53:12 -05:00
|
|
|
let l:executable = ale_linters#php#phpmd#GetExecutable(a:buffer)
|
|
|
|
|
|
|
|
return ale#Escape(l:executable)
|
|
|
|
\ . ' %s text '
|
2017-04-15 20:24:08 -04:00
|
|
|
\ . ale#Var(a:buffer, 'php_phpmd_ruleset')
|
2017-04-15 08:35:54 -04:00
|
|
|
\ . ' --ignore-violations-on-exit %t'
|
|
|
|
endfunction
|
|
|
|
|
2017-02-01 11:09:33 -05:00
|
|
|
function! ale_linters#php#phpmd#Handle(buffer, lines) abort
|
|
|
|
" Matches against lines like the following:
|
|
|
|
"
|
|
|
|
" /path/to/some-filename.php:18 message
|
2017-10-22 12:56:09 -04:00
|
|
|
let l:pattern = '^.*:\(\d\+\)\s\+\(.\+\)$'
|
2017-02-01 11:09:33 -05:00
|
|
|
let l:output = []
|
|
|
|
|
2017-04-17 19:35:53 -04:00
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2017-02-01 11:09:33 -05:00
|
|
|
call add(l:output, {
|
|
|
|
\ 'lnum': l:match[1] + 0,
|
|
|
|
\ 'text': l:match[2],
|
|
|
|
\ 'type': 'W',
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('php', {
|
|
|
|
\ 'name': 'phpmd',
|
2017-11-05 13:53:12 -05:00
|
|
|
\ 'executable_callback': 'ale_linters#php#phpmd#GetExecutable',
|
2017-04-15 08:35:54 -04:00
|
|
|
\ 'command_callback': 'ale_linters#php#phpmd#GetCommand',
|
2017-02-01 11:09:33 -05:00
|
|
|
\ 'callback': 'ale_linters#php#phpmd#Handle',
|
|
|
|
\})
|