diff --git a/README.md b/README.md index 8996c98..52277d7 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ name. That seems to be the fairest way to arrange this table. | MATLAB | [mlint](https://www.mathworks.com/help/matlab/ref/mlint.html) | | OCaml | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-integration-ocaml-merlin` for configuration instructions | Perl | [perl -c](https://perl.org/), [perl-critic](https://metacpan.org/pod/Perl::Critic) | -| PHP | [hack](http://hacklang.org/), [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) | +| PHP | [hack](http://hacklang.org/), [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer), [phpmd](https://phpmd.org) | | Pug | [pug-lint](https://github.com/pugjs/pug-lint) | | Puppet | [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) | | Python | [flake8](http://flake8.pycqa.org/en/latest/), [mypy](http://mypy-lang.org/), [pylint](https://www.pylint.org/) | diff --git a/ale_linters/php/phpmd.vim b/ale_linters/php/phpmd.vim new file mode 100644 index 0000000..7343253 --- /dev/null +++ b/ale_linters/php/phpmd.vim @@ -0,0 +1,41 @@ +" Author: medains +" Description: phpmd for PHP files + +" 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#Handle(buffer, lines) abort + " Matches against lines like the following: + " + " /path/to/some-filename.php:18 message + let l:pattern = '^.*:\(\d\+\)\t\(.\+\)$' + let l:output = [] + + for l:line in a:lines + let l:match = matchlist(l:line, l:pattern) + + if len(l:match) == 0 + continue + endif + + " vcol is Needed to indicate that the column is a character. + call add(l:output, { + \ 'bufnr': a:buffer, + \ 'lnum': l:match[1] + 0, + \ 'vcol': 0, + \ 'col': 0, + \ 'text': l:match[2], + \ 'type': 'W', + \ 'nr': -1, + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('php', { +\ 'name': 'phpmd', +\ 'executable': 'phpmd', +\ 'command': g:ale#util#stdin_wrapper . ' .php phpmd %s text ' . g:ale_php_phpmd_ruleset . ' --ignore-violations-on-exit', +\ 'callback': 'ale_linters#php#phpmd#Handle', +\}) diff --git a/doc/ale.txt b/doc/ale.txt index 28b5eee..187251f 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -35,6 +35,7 @@ CONTENTS *ale-contents* 4.23. python-mypy.....................|ale-linter-options-python-mypy| 4.24. python-pylint...................|ale-linter-options-python-pylint| 4.25. erlang..........................|ale-linter-options-erlang| + 4.26. phpmd...........................|ale-linter-options-phpmd| 5. Linter Integration Notes.............|ale-linter-integration| 5.1. merlin..........................|ale-linter-integration-ocaml-merlin| 5.2. rust.............................|ale-integration-rust| @@ -93,7 +94,7 @@ The following languages and tools are supported. * MATLAB: 'mlint' * OCaml: 'merlin' (see |ale-linter-integration-ocaml-merlin|) * Perl: 'perl' (-c flag), 'perlcritic' -* PHP: 'hack', 'php' (-l flag), 'phpcs' +* PHP: 'hack', 'php' (-l flag), 'phpcs', 'phpmd' * Pug: 'pug-lint' * Puppet: 'puppet', 'puppet-lint' * Python: 'flake8', 'mypy', 'pylint' @@ -880,6 +881,17 @@ g:ale_erlang_erlc_options *g:ale_erlang_erlc_options* This variable controls additional parameters passed to `erlc`, such as `-I` or `-pa`. +------------------------------------------------------------------------------ +4.26. phpmd *ale-linter-options-phpmd* + +g:ale_php_phpmd_ruleset *g:ale_php_phpmd_ruleset* + + Type: |String| + Default: 'cleancode,codesize,controversial,design,naming,unusedcode' + + This variable controls the ruleset used by phpmd. Default is to use all of + the available phpmd rulesets + =============================================================================== 5. Linter Integration Notes *ale-linter-integration*