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.
1 " Author: Magnus Ottenklinger - https://github.com/evnu
3 let g:ale_erlang_erlc_executable = get(g:, 'ale_erlang_erlc_executable', 'erlc')
4 let g:ale_erlang_erlc_options = get(g:, 'ale_erlang_erlc_options', '')
6 function! ale_linters#erlang#erlc#GetExecutable(buffer) abort
7 return ale#Var(a:buffer, 'erlang_erlc_executable')
10 function! ale_linters#erlang#erlc#GetCommand(buffer) abort
11 let l:output_file = ale#util#Tempname()
12 call ale#command#ManageFile(a:buffer, l:output_file)
14 let l:command = ale#Escape(ale_linters#erlang#erlc#GetExecutable(a:buffer))
15 \ . ' -o ' . ale#Escape(l:output_file)
16 \ . ' ' . ale#Var(a:buffer, 'erlang_erlc_options')
22 function! ale_linters#erlang#erlc#Handle(buffer, lines) abort
23 " Matches patterns like the following:
25 " error.erl:4: variable 'B' is unbound
26 " error.erl:3: Warning: function main/0 is unused
27 " error.erl:4: Warning: variable 'A' is unused
28 let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+:)? (Warning: )?(.+)$'
30 " parse_transforms are a special case. The error message does not indicate a location:
31 " error.erl: undefined parse transform 'some_parse_transform'
32 let l:pattern_parse_transform = '\v(undefined parse transform .*)$'
35 let l:pattern_no_module_definition = '\v(no module definition)$'
36 let l:pattern_unused = '\v(.* is unused)$'
38 let l:is_hrl = fnamemodify(bufname(a:buffer), ':e') is# 'hrl'
41 let l:match = matchlist(l:line, l:pattern)
43 " Determine if the output indicates an error. We distinguish between two cases:
45 " 1) normal errors match l:pattern
46 " 2) parse_transform errors match l:pattern_parse_transform
48 " If none of the patterns above match, the line can be ignored
49 if len(l:match) == 0 " not a 'normal' warning or error
50 let l:match_parse_transform = matchlist(l:line, l:pattern_parse_transform)
52 if len(l:match_parse_transform) == 0 " also not a parse_transform error
61 \ 'text': l:match_parse_transform[0],
67 let l:line = l:match[2]
68 let l:warning_or_text = l:match[4]
69 let l:text = l:match[5]
71 " If this file is a header .hrl, ignore the following expected messages:
72 " - 'no module definition'
75 \ match(l:text, l:pattern_no_module_definition) != -1
76 \ || match(l:text, l:pattern_unused) != -1
81 if !empty(l:warning_or_text)
99 call ale#linter#Define('erlang', {
101 \ 'executable': function('ale_linters#erlang#erlc#GetExecutable'),
102 \ 'command': function('ale_linters#erlang#erlc#GetCommand'),
103 \ 'callback': 'ale_linters#erlang#erlc#Handle',