Fix #710 - Show hlint suggestions as info items, and include end line and column numbers
This commit is contained in:
parent
5a6ffc2804
commit
aa94d0902a
@ -2,17 +2,30 @@
|
||||
" Description: hlint for Haskell files
|
||||
|
||||
function! ale_linters#haskell#hlint#Handle(buffer, lines) abort
|
||||
if empty(a:lines)
|
||||
return []
|
||||
endif
|
||||
|
||||
let l:errors = json_decode(join(a:lines, ''))
|
||||
|
||||
let l:output = []
|
||||
|
||||
for l:error in l:errors
|
||||
if l:error.severity ==# 'Error'
|
||||
let l:type = 'E'
|
||||
elseif l:error.severity ==# 'Suggestion'
|
||||
let l:type = 'I'
|
||||
else
|
||||
let l:type = 'W'
|
||||
endif
|
||||
|
||||
call add(l:output, {
|
||||
\ 'bufnr': a:buffer,
|
||||
\ 'lnum': l:error.startLine + 0,
|
||||
\ 'col': l:error.startColumn + 0,
|
||||
\ 'lnum': str2nr(l:error.startLine),
|
||||
\ 'col': str2nr(l:error.startColumn),
|
||||
\ 'end_lnum': str2nr(l:error.endLine),
|
||||
\ 'end_col': str2nr(l:error.endColumn),
|
||||
\ 'text': l:error.severity . ': ' . l:error.hint . '. Found: ' . l:error.from . ' Why not: ' . l:error.to,
|
||||
\ 'type': l:error.severity ==# 'Error' ? 'E' : 'W',
|
||||
\ 'type': l:type,
|
||||
\})
|
||||
endfor
|
||||
|
||||
|
80
test/handler/test_hlint_handler.vader
Normal file
80
test/handler/test_hlint_handler.vader
Normal file
@ -0,0 +1,80 @@
|
||||
Before:
|
||||
runtime! ale_linters/haskell/hlint.vim
|
||||
|
||||
After:
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The hlint handler should parse items correctly):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 1,
|
||||
\ 'col': 4,
|
||||
\ 'end_lnum': 3,
|
||||
\ 'end_col': 2,
|
||||
\ 'text': 'Error: Do something. Found: [Char] Why not: String',
|
||||
\ 'type': 'E',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 2,
|
||||
\ 'col': 4,
|
||||
\ 'end_lnum': 7,
|
||||
\ 'end_col': 2,
|
||||
\ 'text': 'Warning: Do something. Found: [Char] Why not: String',
|
||||
\ 'type': 'W',
|
||||
\ },
|
||||
\ {
|
||||
\ 'lnum': 73,
|
||||
\ 'col': 25,
|
||||
\ 'end_lnum': 73,
|
||||
\ 'end_col': 31,
|
||||
\ 'text': 'Suggestion: Use String. Found: [Char] Why not: String',
|
||||
\ 'type': 'I',
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#haskell#hlint#Handle(bufnr(''), [json_encode([
|
||||
\ {
|
||||
\ 'module': 'Main',
|
||||
\ 'decl': 'foo',
|
||||
\ 'severity': 'Error',
|
||||
\ 'hint': 'Do something',
|
||||
\ 'file': '-',
|
||||
\ 'startLine': 1,
|
||||
\ 'startColumn': 4,
|
||||
\ 'endLine': 3,
|
||||
\ 'endColumn': 2,
|
||||
\ 'from': '[Char]',
|
||||
\ 'to': 'String',
|
||||
\ },
|
||||
\ {
|
||||
\ 'module': 'Main',
|
||||
\ 'decl': 'foo',
|
||||
\ 'severity': 'Warning',
|
||||
\ 'hint': 'Do something',
|
||||
\ 'file': '-',
|
||||
\ 'startLine': 2,
|
||||
\ 'startColumn': 4,
|
||||
\ 'endLine': 7,
|
||||
\ 'endColumn': 2,
|
||||
\ 'from': '[Char]',
|
||||
\ 'to': 'String',
|
||||
\ },
|
||||
\ {
|
||||
\ 'module': 'Main',
|
||||
\ 'decl': 'myFocusedBorderColor',
|
||||
\ 'severity': 'Suggestion',
|
||||
\ 'hint': 'Use String',
|
||||
\ 'file': '-',
|
||||
\ 'startLine': 73,
|
||||
\ 'startColumn': 25,
|
||||
\ 'endLine': 73,
|
||||
\ 'endColumn': 31,
|
||||
\ 'from': '[Char]',
|
||||
\ 'to': 'String',
|
||||
\ },
|
||||
\ ])])
|
||||
|
||||
Execute(The hlint handler should handle empty output):
|
||||
AssertEqual
|
||||
\ [],
|
||||
\ ale_linters#haskell#hlint#Handle(bufnr(''), [])
|
Loading…
Reference in New Issue
Block a user