improved the sml linter (#445)
* improved the sml linter * made matching operator agnostic to user settings * added tests for sml
This commit is contained in:
parent
434283ed1a
commit
cc8eb05860
@ -12,20 +12,34 @@ function! ale_linters#sml#smlnj#Handle(buffer, lines) abort
|
||||
|
||||
let l:out = []
|
||||
let l:pattern = '^.*\:\([0-9\.]\+\)\ \(\w\+\)\:\ \(.*\)'
|
||||
let l:pattern2 = '^.*\:\([0-9]\+\)\.\?\([0-9]\+\).* \(\(Warning\|Error\): .*\)'
|
||||
|
||||
for l:line in a:lines
|
||||
let l:match = matchlist(l:line, l:pattern)
|
||||
let l:match2 = matchlist(l:line, l:pattern2)
|
||||
|
||||
if len(l:match) == 0
|
||||
if len(l:match2) != 0
|
||||
call add(l:out, {
|
||||
\ 'bufnr': a:buffer,
|
||||
\ 'lnum': l:match2[1] + 0,
|
||||
\ 'col' : l:match2[2] - 1,
|
||||
\ 'text': l:match2[3],
|
||||
\ 'type': l:match2[3] =~# '^Warning' ? 'W' : 'E',
|
||||
\})
|
||||
continue
|
||||
endif
|
||||
|
||||
let l:match = matchlist(l:line, l:pattern)
|
||||
|
||||
if len(l:match) != 0
|
||||
call add(l:out, {
|
||||
\ 'bufnr': a:buffer,
|
||||
\ 'lnum': l:match[1] + 0,
|
||||
\ 'text': l:match[2] . ': ' . l:match[3],
|
||||
\ 'type': l:match[2] ==# 'error' ? 'E' : 'W',
|
||||
\})
|
||||
continue
|
||||
endif
|
||||
|
||||
endfor
|
||||
|
||||
return l:out
|
||||
|
91
test/handler/test_sml_handler.vader
Normal file
91
test/handler/test_sml_handler.vader
Normal file
@ -0,0 +1,91 @@
|
||||
Before:
|
||||
runtime ale_linters/sml/smlnj.vim
|
||||
|
||||
Execute (Testing on EOF error):
|
||||
AssertEqual [
|
||||
\ {
|
||||
\ 'bufnr': 42,
|
||||
\ 'lnum': 2,
|
||||
\ 'col': 15,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'Error: syntax error found at EOF',
|
||||
\ },
|
||||
\],
|
||||
\ ale_linters#sml#smlnj#Handle(42, [
|
||||
\ "Standard ML of New Jersey v110.78 [built: Thu Jul 23 11:21:58 2015]",
|
||||
\ "[opening a.sml]",
|
||||
\ "a.sml:2.16 Error: syntax error found at EOF",
|
||||
\ '/usr/lib/smlnj/bin/sml: Fatal error -- Uncaught exception Compile with "syntax error" raised at ../compiler/Parse/main/smlfile.sml:15.24-15.46',
|
||||
\])
|
||||
|
||||
Execute (Testing if the handler can handle multiple errors on the same line):
|
||||
AssertEqual [
|
||||
\ {
|
||||
\ 'bufnr': 42,
|
||||
\ 'lnum': 1,
|
||||
\ 'col': 5,
|
||||
\ 'type': 'E',
|
||||
\ 'text': "Error: can't find function arguments in clause",
|
||||
\ },
|
||||
\ {
|
||||
\ 'bufnr': 42,
|
||||
\ 'lnum': 1,
|
||||
\ 'col': 12,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'Error: unbound variable or constructor: wow',
|
||||
\ },
|
||||
\],
|
||||
\ ale_linters#sml#smlnj#Handle(42, [
|
||||
\ "Standard ML of New Jersey v110.78 [built: Thu Jul 23 11:21:58 2015]",
|
||||
\ "[opening test.sml]",
|
||||
\ "a.sml:1.6-1.10 Error: can't find function arguments in clause",
|
||||
\ "a.sml:1.13-1.16 Error: unbound variable or constructor: wow",
|
||||
\ "/usr/lib/smlnj/bin/sml: Fatal error -- Uncaught exception Error with 0",
|
||||
\ "raised at ../compiler/TopLevel/interact/evalloop.sml:66.19-66.27",
|
||||
\])
|
||||
|
||||
Execute (Testing rarer errors):
|
||||
AssertEqual [
|
||||
\ {
|
||||
\ 'bufnr': 42,
|
||||
\ 'lnum': 5,
|
||||
\ 'col': 18,
|
||||
\ 'type': 'E',
|
||||
\ 'text': "Error: syntax error found at ID",
|
||||
\ },
|
||||
\ {
|
||||
\ 'bufnr': 42,
|
||||
\ 'lnum': 7,
|
||||
\ 'col': 0,
|
||||
\ 'type': 'E',
|
||||
\ 'text': "Error: value type in structure doesn't match signature spec",
|
||||
\ },
|
||||
\],
|
||||
\ ale_linters#sml#smlnj#Handle(42, [
|
||||
\ "Standard ML of New Jersey v110.78 [built: Thu Jul 23 11:21:58 2015]",
|
||||
\ "[opening test.sml]",
|
||||
\ "a.sml:5.19 Error: syntax error found at ID",
|
||||
\ "a.sml:7.1-9.27 Error: value type in structure doesn't match signature spec",
|
||||
\ "/usr/lib/smlnj/bin/sml: Fatal error -- Uncaught exception Error with 0",
|
||||
\ "raised at ../compiler/TopLevel/interact/evalloop.sml:66.19-66.27",
|
||||
\])
|
||||
|
||||
Execute (Testing a warning):
|
||||
AssertEqual [
|
||||
\ {
|
||||
\ 'bufnr': 42,
|
||||
\ 'lnum': 4,
|
||||
\ 'col': 4,
|
||||
\ 'type': 'W',
|
||||
\ 'text': "Warning: match nonexhaustive",
|
||||
\ },
|
||||
\],
|
||||
\ ale_linters#sml#smlnj#Handle(42, [
|
||||
\ "Standard ML of New Jersey v110.78 [built: Thu Jul 23 11:21:58 2015]",
|
||||
\ "[opening a.sml]",
|
||||
\ "a.sml:4.5-4.12 Warning: match nonexhaustive",
|
||||
\ "0 => ...",
|
||||
\ "val f = fn : int -> int",
|
||||
\ "-",
|
||||
\])
|
||||
|
Loading…
Reference in New Issue
Block a user