1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
" Author: awlayton <alex@layton.in>
" Description: mlint for MATLAB files
let g:ale_matlab_mlint_executable =
\ get(g:, 'ale_matlab_mlint_executable', 'mlint')
function! ale_linters#matlab#mlint#GetExecutable(buffer) abort
return g:ale_matlab_mlint_executable
endfunction
function! ale_linters#matlab#mlint#GetCommand(buffer) abort
let l:executable = ale_linters#matlab#mlint#GetExecutable(a:buffer)
return l:executable . ' -id %t'
endfunction
function! ale_linters#matlab#mlint#Handle(buffer, lines) abort
" 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_callback': 'ale_linters#matlab#mlint#GetExecutable',
\ 'command_callback': 'ale_linters#matlab#mlint#GetCommand',
\ 'output_stream': 'stderr',
\ 'callback': 'ale_linters#matlab#mlint#Handle',
\})
|