fix: Handle ranges for the remark linter #1207

This commit is contained in:
Adrián González Rus 2018-03-22 11:40:47 +01:00
parent 0678eb1f45
commit 87217ae347
2 changed files with 22 additions and 7 deletions

View File

@ -1,18 +1,24 @@
" Author rhysd https://rhysd.github.io/ " Author rhysd https://rhysd.github.io/, Dirk Roorda (dirkroorda), Adrián González Rus (@adrigzr)
" Description: remark-lint for Markdown files " Description: remark-lint for Markdown files
function! ale_linters#markdown#remark_lint#Handle(buffer, lines) abort function! ale_linters#markdown#remark_lint#Handle(buffer, lines) abort
" matches: ' 1:4 warning Incorrect list-item indent: add 1 space list-item-indent remark-lint' " matches: ' 1:4 warning Incorrect list-item indent: add 1 space list-item-indent remark-lint'
let l:pattern = '^ \+\(\d\+\):\(\d\+\) \(warning\|error\) \(.\+\)$' " matches: ' 18:71-19:1 error Missing new line after list item list-item-spacing remark-lint',
let l:pattern = '^ \+\(\d\+\):\(\d\+\)\(-\(\d\+\):\(\d\+\)\)\? \(warning\|error\) \(.\+\)$'
let l:output = [] let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern) for l:match in ale#util#GetMatches(a:lines, l:pattern)
call add(l:output, { let l:item = {
\ 'lnum': l:match[1] + 0, \ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0, \ 'col': l:match[2] + 0,
\ 'type': l:match[3] is# 'error' ? 'E' : 'W', \ 'type': l:match[6] is# 'error' ? 'E' : 'W',
\ 'text': l:match[4], \ 'text': l:match[7],
\}) \}
if l:match[3] isnot# ''
let l:item.end_lnum = l:match[4] + 0
let l:item.end_col = l:match[5] + 0
endif
call add(l:output, l:item)
endfor endfor
return l:output return l:output

View File

@ -19,12 +19,21 @@ Execute(Warning and error messages should be handled correctly):
\ 'type': 'E', \ 'type': 'E',
\ 'text': 'Incorrect list-item indent: remove 1 space list-item-indent remark-lint', \ 'text': 'Incorrect list-item indent: remove 1 space list-item-indent remark-lint',
\ }, \ },
\ {
\ 'lnum': 18,
\ 'col': 71,
\ 'end_lnum': 19,
\ 'end_col': 1,
\ 'type': 'E',
\ 'text': 'Missing new line after list item list-item-spacing remark-lint',
\ },
\ ], \ ],
\ ale_linters#markdown#remark_lint#Handle(1, [ \ ale_linters#markdown#remark_lint#Handle(1, [
\ 'foo.md', \ 'foo.md',
\ ' 1:4 warning Incorrect list-item indent: add 1 space list-item-indent remark-lint', \ ' 1:4 warning Incorrect list-item indent: add 1 space list-item-indent remark-lint',
\ ' 3:5 error Incorrect list-item indent: remove 1 space list-item-indent remark-lint', \ ' 3:5 error Incorrect list-item indent: remove 1 space list-item-indent remark-lint',
\ ' 18:71-19:1 error Missing new line after list item list-item-spacing remark-lint',
\ '', \ '',
\ '⚠ 1 warnings', \ '⚠ 1 warnings',
\ '✘ 1 errors', \ '✘ 2 errors',
\]) \])