summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormedains <medains@github.com.fake>2017-02-01 16:09:33 +0000
committermedains <medains@github.com.fake>2017-02-01 16:28:51 +0000
commitff096124c6d128bef222aa6954da636c075b05d8 (patch)
tree2534a4502691dbf0bd3f723d32df6134f9ef7d73
parent512b6e00d9379700d65dbf7701dc9631f62866d8 (diff)
downloadale-ff096124c6d128bef222aa6954da636c075b05d8.zip
Linter addition of PHP Mess Detector
-rw-r--r--README.md2
-rw-r--r--ale_linters/php/phpmd.vim41
-rw-r--r--doc/ale.txt14
3 files changed, 55 insertions, 2 deletions
diff --git a/README.md b/README.md
index 1b59b632..cb976c0f 100644
--- a/README.md
+++ b/README.md
@@ -75,7 +75,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 00000000..73432538
--- /dev/null
+++ b/ale_linters/php/phpmd.vim
@@ -0,0 +1,41 @@
+" Author: medains <https://github.com/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 4bed2e02..c8e4ff40 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*