Show problems from other files for lessc

This commit is contained in:
w0rp 2017-11-12 11:35:01 +00:00
parent cd5da50531
commit 7edcb2210b
2 changed files with 78 additions and 2 deletions

View File

@ -24,17 +24,24 @@ function! ale_linters#less#lessc#GetCommand(buffer) abort
endfunction
function! ale_linters#less#lessc#Handle(buffer, lines) abort
let l:dir = expand('#' . a:buffer . ':p:h')
" Matches patterns like the following:
let l:pattern = '^\(\w\+\): \(.\{-}\) in \(.\{-}\) on line \(\d\+\), column \(\d\+\):$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
call add(l:output, {
let l:item = {
\ 'lnum': l:match[4] + 0,
\ 'col': l:match[5] + 0,
\ 'text': l:match[2],
\ 'type': 'E',
\})
\}
if l:match[3] isnot# '-'
let l:item.filename = ale#path#GetAbsPath(l:dir, l:match[3])
endif
call add(l:output, l:item)
endfor
return l:output

View File

@ -0,0 +1,69 @@
Before:
call ale#test#SetDirectory('/testplugin/test/handler')
call ale#test#SetFilename('testfile.less')
runtime ale_linters/less/lessc.vim
After:
call ale#test#RestoreDirectory()
call ale#linter#Reset()
Execute(The lessc handler should handle errors for the current file correctly):
AssertEqual
\ [
\ {
\ 'lnum': 2,
\ 'col': 1,
\ 'type': 'E',
\ 'text': 'Unrecognised input. Possibly missing something',
\ },
\ ],
\ ale_linters#less#lessc#Handle(bufnr(''), [
\ 'ParseError: Unrecognised input. Possibly missing something in - on line 2, column 1:',
\ '1 vwewww',
\ '2 ',
\])
Execute(The lessc handler should handle errors for other files in the same directory correctly):
AssertEqual
\ [
\ {
\ 'lnum': 2,
\ 'col': 1,
\ 'type': 'E',
\ 'text': 'Unrecognised input. Possibly missing something',
\ 'filename': ale#path#Winify(g:dir . '/imported.less')
\ },
\ {
\ 'lnum': 2,
\ 'col': 1,
\ 'type': 'E',
\ 'text': 'Unrecognised input. Possibly missing something',
\ 'filename': ale#path#Winify(g:dir . '/imported.less')
\ },
\ ],
\ ale_linters#less#lessc#Handle(bufnr(''), [
\ 'ParseError: Unrecognised input. Possibly missing something in imported.less on line 2, column 1:',
\ '1 vwewww',
\ '2 ',
\ 'ParseError: Unrecognised input. Possibly missing something in ./imported.less on line 2, column 1:',
\ '1 vwewww',
\ '2 ',
\])
Execute(The lessc handler should handle errors for files in directories above correctly):
AssertEqual
\ [
\ {
\ 'lnum': 2,
\ 'col': 1,
\ 'type': 'E',
\ 'text': 'Unrecognised input. Possibly missing something',
\ 'filename': ale#path#Winify(g:dir . '/../imported2.less')
\ },
\ ],
\ ale_linters#less#lessc#Handle(bufnr(''), [
\ 'ParseError: Unrecognised input. Possibly missing something in ../imported2.less on line 2, column 1:',
\ '1 vwewww',
\ '2 ',
\])