summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitri Vereshchagin <dmitri.vereshchagin@gmail.com>2024-07-12 03:40:38 +0300
committerGitHub <noreply@github.com>2024-07-12 09:40:38 +0900
commit48d73c87c3c321e6298755abc5449267192d07e6 (patch)
tree762b9ca51b2138d0c893da73886524f667eea811
parent5c635d5038b9faae88a432d7f2f1b93ef3cf44f3 (diff)
downloadale-48d73c87c3c321e6298755abc5449267192d07e6.zip
Refactor SyntaxErl linter file (#4807)
-rw-r--r--ale_linters/erlang/syntaxerl.vim40
-rw-r--r--test/linter/test_erlang_syntaxerl.vader8
2 files changed, 25 insertions, 23 deletions
diff --git a/ale_linters/erlang/syntaxerl.vim b/ale_linters/erlang/syntaxerl.vim
index 5d555a8d..bd984fef 100644
--- a/ale_linters/erlang/syntaxerl.vim
+++ b/ale_linters/erlang/syntaxerl.vim
@@ -3,29 +3,13 @@
call ale#Set('erlang_syntaxerl_executable', 'syntaxerl')
-function! ale_linters#erlang#syntaxerl#RunHelpCommand(buffer) abort
- let l:executable = ale#Var(a:buffer, 'erlang_syntaxerl_executable')
-
- return ale#command#Run(
- \ a:buffer,
- \ ale#Escape(l:executable) . ' -h',
- \ function('ale_linters#erlang#syntaxerl#GetCommand'),
- \)
-endfunction
-
-function! ale_linters#erlang#syntaxerl#GetCommand(buffer, output, meta) abort
- let l:use_b_option = match(a:output, '\C\V-b, --base\>') > -1
-
- return '%e' . (l:use_b_option ? ' -b %s %t' : ' %t')
-endfunction
-
function! ale_linters#erlang#syntaxerl#Handle(buffer, lines) abort
let l:pattern = '\v\C:(\d+):( warning:)? (.+)'
let l:loclist = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
call add(l:loclist, {
- \ 'lnum': l:match[1] + 0,
+ \ 'lnum': str2nr(l:match[1]),
\ 'text': l:match[3],
\ 'type': empty(l:match[2]) ? 'E' : 'W',
\})
@@ -34,9 +18,27 @@ function! ale_linters#erlang#syntaxerl#Handle(buffer, lines) abort
return l:loclist
endfunction
+function! s:GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'erlang_syntaxerl_executable')
+endfunction
+
+function! s:GetCommand(buffer) abort
+ let l:Callback = function('s:GetCommandFromHelpOutput')
+
+ return ale#command#Run(a:buffer, '%e -h', l:Callback, {
+ \ 'executable': s:GetExecutable(a:buffer),
+ \})
+endfunction
+
+function! s:GetCommandFromHelpOutput(buffer, output, metadata) abort
+ let l:has_b_option = match(a:output, '\V\C-b, --base\>') > -1
+
+ return l:has_b_option ? '%e -b %s %t' : '%e %t'
+endfunction
+
call ale#linter#Define('erlang', {
\ 'name': 'syntaxerl',
-\ 'executable': {b -> ale#Var(b, 'erlang_syntaxerl_executable')},
-\ 'command': {b -> ale_linters#erlang#syntaxerl#RunHelpCommand(b)},
\ 'callback': 'ale_linters#erlang#syntaxerl#Handle',
+\ 'executable': function('s:GetExecutable'),
+\ 'command': function('s:GetCommand'),
\})
diff --git a/test/linter/test_erlang_syntaxerl.vader b/test/linter/test_erlang_syntaxerl.vader
index e7cc26ea..52218667 100644
--- a/test/linter/test_erlang_syntaxerl.vader
+++ b/test/linter/test_erlang_syntaxerl.vader
@@ -11,11 +11,11 @@ Execute (The default commands should be correct):
\]
Execute (The executable should be configurable):
- let b:ale_erlang_syntaxerl_executable = 'foobar'
+ let b:ale_erlang_syntaxerl_executable = '/path/to/syntaxerl'
- AssertLinter 'foobar', [
- \ ale#Escape('foobar') . ' -h',
- \ ale#Escape('foobar') . ' %t',
+ AssertLinter '/path/to/syntaxerl', [
+ \ ale#Escape('/path/to/syntaxerl') . ' -h',
+ \ ale#Escape('/path/to/syntaxerl') . ' %t',
\]
Execute (The -b option should be used when available):