From 95373ddab5966e5975c7d1a9f52ddbbeeb664cc0 Mon Sep 17 00:00:00 2001 From: Alex Layton Date: Mon, 24 Oct 2016 15:32:52 -0400 Subject: [PATCH] Add support for mlint, a MATLAB linter (#145) * Add support for mlint, a MATLAB linter * Fix mlint linter as requested * Clean up leftover loaded flag for mlint --- README.md | 1 + ale_linters/matlab/mlint.vim | 55 ++++++++++++++++++++++++++++++++++++ doc/ale.txt | 1 + 3 files changed, 57 insertions(+) create mode 100644 ale_linters/matlab/mlint.vim diff --git a/README.md b/README.md index 8c0e8d7..4cbebcd 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ name. That seems to be the fairest way to arrange this table. | JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/) | | JSON | [jsonlint](http://zaa.ch/jsonlint/) | | Lua | [luacheck](https://github.com/mpeterv/luacheck) | +| MATLAB | [mlint](https://www.mathworks.com/help/matlab/ref/mlint.html) | | Perl | [perl -c](https://perl.org/), [perl-critic](https://metacpan.org/pod/Perl::Critic) | | PHP | [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) | | Pug | [pug-lint](https://github.com/pugjs/pug-lint) | diff --git a/ale_linters/matlab/mlint.vim b/ale_linters/matlab/mlint.vim new file mode 100644 index 0000000..e1e6cf0 --- /dev/null +++ b/ale_linters/matlab/mlint.vim @@ -0,0 +1,55 @@ +" Author: awlayton +" Description: mlint for MATLAB files + +let g:ale_matlab_mlint_executable = +\ get(g:, 'ale_matlab_mlint_executable', 'mlint') + +function! ale_linters#matlab#mlint#Handle(buffer, lines) + " Matches patterns like the following: + " + " L 27 (C 1): FNDEF: Terminate statement with semicolon to suppress output. + " L 30 (C 13-15): FNDEF: A quoted string is unterminated. + let l:pattern = '^L \(\d\+\) (C \([0-9-]\+\)): \([A-Z]\+\): \(.\+\)$' + let l:output = [] + + for l:line in a:lines + let l:match = matchlist(l:line, l:pattern) + + if len(l:match) == 0 + continue + endif + + let l:lnum = l:match[1] + 0 + let l:col = l:match[2] + 0 + let l:code = l:match[3] + let l:text = l:match[4] + + " Suppress erroneous waring about filename + " TODO: Enable this error when copying filename is supported + if l:code ==# 'FNDEF' + continue + endif + + " vcol is needed to indicate that the column is a character. + call add(l:output, { + \ 'bufnr': a:buffer, + \ 'lnum': l:lnum, + \ 'vcol': 0, + \ 'col': l:col, + \ 'text': l:text, + \ 'type': 'W', + \ 'nr': -1, + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('matlab', { +\ 'name': 'mlint', +\ 'executable': 'mlint', +\ 'command': g:ale#util#stdin_wrapper . +\ ' .m ' . g:ale_matlab_mlint_executable . ' -id', +\ 'output_stream': 'stderr', +\ 'callback': 'ale_linters#matlab#mlint#Handle', +\}) diff --git a/doc/ale.txt b/doc/ale.txt index 52702b2..c1abaa7 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -67,6 +67,7 @@ The following languages and tools are supported. * JavaScript: 'eslint', 'jscs', 'jshint' * JSON: 'jsonlint' * Lua: 'luacheck' +* MATLAB: 'mlint' * Perl: 'perl' (-c flag), 'perlcritic' * PHP: 'php' (-l flag), 'phpcs' * Pug: 'pug-lint'