summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-01-22 13:51:57 +0000
committerw0rp <devw0rp@gmail.com>2017-01-22 13:51:57 +0000
commite4a4fcd26bff47b3611887167a0510a5e29cbe3b (patch)
tree2c5c5d51b87bab4d3b209bc5f9fb1895e7ff4b9b
parentcae153b3ac506bf391b6d57a32a00b0c1e046f40 (diff)
downloadale-e4a4fcd26bff47b3611887167a0510a5e29cbe3b.zip
Make the Erlang linter code match the style used in the rest of the codebase. Make the options match the new standard.
-rw-r--r--ale_linters/erlang/erlc.vim139
-rw-r--r--doc/ale.txt4
2 files changed, 75 insertions, 68 deletions
diff --git a/ale_linters/erlang/erlc.vim b/ale_linters/erlang/erlc.vim
index 0e3cc2fa..1cd35d06 100644
--- a/ale_linters/erlang/erlc.vim
+++ b/ale_linters/erlang/erlc.vim
@@ -1,89 +1,96 @@
" Author: Magnus Ottenklinger - https://github.com/evnu
-function! ale_linters#erlang#erlc#Handle(buffer, lines)
- " Matches patterns like the following:
- "
- " error.erl:4: variable 'B' is unbound
- " error.erl:3: Warning: function main/0 is unused
- " error.erl:4: Warning: variable 'A' is unused
- let l:pattern = '\v^([^:]+):(\d+): (Warning: )?(.+)$'
+let g:ale_erlang_erlc_options = get(g:, 'ale_erlang_erlc_options', '')
- " parse_transforms are a special case. The error message does not indicate a location:
- " error.erl: undefined parse transform 'some_parse_transform'
- let l:pattern_parse_transform = '\v(undefined parse transform .*)$'
- let l:output = []
+function! ale_linters#erlang#erlc#GetCommand(buffer) abort
+ return g:ale#util#stdin_wrapper . ' .erl erlc ' . g:ale_erlang_erlc_options
+endfunction
- let l:pattern_no_module_definition = '\v(no module definition)$'
- let l:pattern_unused = '\v(.* is unused)$'
+function! ale_linters#erlang#erlc#Handle(buffer, lines) abort
+ " Matches patterns like the following:
+ "
+ " error.erl:4: variable 'B' is unbound
+ " error.erl:3: Warning: function main/0 is unused
+ " error.erl:4: Warning: variable 'A' is unused
+ let l:pattern = '\v^([^:]+):(\d+): (Warning: )?(.+)$'
- let l:is_hrl = fnamemodify(bufname(a:buffer), ':e') ==# 'hrl'
+ " parse_transforms are a special case. The error message does not indicate a location:
+ " error.erl: undefined parse transform 'some_parse_transform'
+ let l:pattern_parse_transform = '\v(undefined parse transform .*)$'
+ let l:output = []
- for l:line in a:lines
- let l:match = matchlist(l:line, l:pattern)
+ let l:pattern_no_module_definition = '\v(no module definition)$'
+ let l:pattern_unused = '\v(.* is unused)$'
- " Determine if the output indicates an error. We distinguish between two cases:
- "
- " 1) normal errors match l:pattern
- " 2) parse_transform errors match l:pattern_parse_transform
- "
- " If none of the patterns above match, the line can be ignored
- if len(l:match) == 0 " not a 'normal' warning or error
+ let l:is_hrl = fnamemodify(bufname(a:buffer), ':e') ==# 'hrl'
+
+ for l:line in a:lines
+ let l:match = matchlist(l:line, l:pattern)
+
+ " Determine if the output indicates an error. We distinguish between two cases:
+ "
+ " 1) normal errors match l:pattern
+ " 2) parse_transform errors match l:pattern_parse_transform
+ "
+ " If none of the patterns above match, the line can be ignored
+ if len(l:match) == 0 " not a 'normal' warning or error
+ let l:match_parse_transform = matchlist(l:line, l:pattern_parse_transform)
+
+ if len(l:match_parse_transform) == 0 " also not a parse_transform error
+ continue
+ endif
- let l:match_parse_transform = matchlist(l:line, l:pattern_parse_transform)
+ call add(l:output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': 0,
+ \ 'vcol': 0,
+ \ 'col': 0,
+ \ 'type': 'E',
+ \ 'text': l:match_parse_transform[0],
+ \ 'nr': -1,
+ \})
- if len(l:match_parse_transform) == 0 " also not a parse_transform error
continue
endif
+ let l:line = l:match[2]
+ let l:warning_or_text = l:match[3]
+ let l:text = l:match[4]
+
+ " If this file is a header .hrl, ignore the following expected messages:
+ " - 'no module definition'
+ " - 'X is unused'
+ if l:is_hrl && (
+ \ match(l:text, l:pattern_no_module_definition) != -1
+ \ || match(l:text, l:pattern_unused) != -1
+ \)
+ continue
+ endif
+
+ if !empty(l:warning_or_text)
+ let l:type = 'W'
+ else
+ let l:type = 'E'
+ endif
+
+ " vcol is Needed to indicate that the column is a character.
call add(l:output, {
\ 'bufnr': a:buffer,
- \ 'lnum': 0,
+ \ 'lnum': l:line,
\ 'vcol': 0,
\ 'col': 0,
- \ 'type': 'E',
- \ 'text': l:match_parse_transform[0],
+ \ 'type': l:type,
+ \ 'text': l:text,
\ 'nr': -1,
\})
- continue
- endif
-
- let l:line = l:match[2]
- let l:warning_or_text = l:match[3]
- let l:text = l:match[4]
-
- " If this file is a header .hrl, ignore the following expected messages:
- " - 'no module definition'
- " - 'X is unused'
- if l:is_hrl &&
- \ (match(l:text, l:pattern_no_module_definition) != -1 ||
- \ match(l:text, l:pattern_unused) != -1)
- continue
- endif
-
- if !empty(l:warning_or_text)
- let l:type = 'W'
- else
- let l:type = 'E'
- endif
-
- " vcol is Needed to indicate that the column is a character.
- call add(l:output, {
- \ 'bufnr': a:buffer,
- \ 'lnum': l:line,
- \ 'vcol': 0,
- \ 'col': 0,
- \ 'type': l:type,
- \ 'text': l:text,
- \ 'nr': -1,
- \})
- endfor
-
- return l:output
+ endfor
+
+ return l:output
endfunction
call ale#linter#Define('erlang', {
\ 'name': 'erlc',
\ 'executable': 'erlc',
-\ 'command': g:ale#util#stdin_wrapper . ' .erl erlc '
-\ . get(g:, 'ale_erlang_erlc_flags', ''),
-\ 'callback': 'ale_linters#erlang#erlc#Handle' })
+\ 'command_callback': 'ale_linters#erlang#erlc#GetCommand',
+\ 'callback': 'ale_linters#erlang#erlc#Handle',
+\})
diff --git a/doc/ale.txt b/doc/ale.txt
index 3421378a..f002f40d 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -830,9 +830,9 @@ g:ale_python_pylint_options *g:ale_python_pylint_options*
`python3 -m pip install --user pylint`).
------------------------------------------------------------------------------
-4.25. erlang *ale-linter-options-erlang*
+4.25. erlang *ale-linter-options-erlang*
-g:ale_erlang_erlc_flags *g:ale_erlang_erlc_flags*
+g:ale_erlang_erlc_options *g:ale_erlang_erlc_options*
Type: |String|
Default: '`''`'