]> git.madduck.net Git - etc/vim.git/blob - ale_linters/php/phpmd.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / ale_linters / php / phpmd.vim
1 " Author: medains <https://github.com/medains>, David Sierra <https://github.com/davidsierradz>
2 " Description: phpmd for PHP files
3
4 let g:ale_php_phpmd_executable = get(g:, 'ale_php_phpmd_executable', 'phpmd')
5
6 " Set to change the ruleset
7 let g:ale_php_phpmd_ruleset = get(g:, 'ale_php_phpmd_ruleset', 'cleancode,codesize,controversial,design,naming,unusedcode')
8
9 function! ale_linters#php#phpmd#GetCommand(buffer) abort
10     return '%e %t text'
11     \   . ale#Pad(ale#Var(a:buffer, 'php_phpmd_ruleset'))
12     \   . ' --ignore-violations-on-exit'
13 endfunction
14
15 function! ale_linters#php#phpmd#Handle(buffer, lines) abort
16     " Matches against lines like the following:
17     "
18     " /path/to/some-filename.php:18 message
19     let l:pattern = '^.*:\(\d\+\)\s\+\(.\+\)$'
20     let l:output = []
21
22     for l:match in ale#util#GetMatches(a:lines, l:pattern)
23         call add(l:output, {
24         \   'lnum': l:match[1] + 0,
25         \   'text': l:match[2],
26         \   'type': 'W',
27         \})
28     endfor
29
30     return l:output
31 endfunction
32
33 call ale#linter#Define('php', {
34 \   'name': 'phpmd',
35 \   'executable': {b -> ale#Var(b, 'php_phpmd_executable')},
36 \   'command': function('ale_linters#php#phpmd#GetCommand'),
37 \   'callback': 'ale_linters#php#phpmd#Handle',
38 \})