2017-11-16 09:12:08 +00:00
|
|
|
" Author: rhysd https://rhysd.github.io
|
|
|
|
" Description: Redpen, a proofreading tool (http://redpen.cc)
|
|
|
|
|
|
|
|
function! ale_linters#markdown#redpen#HandleErrors(buffer, lines) abort
|
|
|
|
" Only one file was passed to redpen. So response array has only one
|
|
|
|
" element.
|
|
|
|
let l:res = json_decode(join(a:lines))[0]
|
2017-11-16 10:28:30 +00:00
|
|
|
let l:output = []
|
2017-11-16 09:12:08 +00:00
|
|
|
for l:err in l:res.errors
|
2017-11-16 10:28:30 +00:00
|
|
|
let l:item = {
|
|
|
|
\ 'text': l:err.message . ' (' . l:err.validator . ')',
|
|
|
|
\ 'type': 'W',
|
|
|
|
\}
|
2017-11-16 09:12:08 +00:00
|
|
|
if has_key(l:err, 'startPosition')
|
2017-11-16 10:28:30 +00:00
|
|
|
let l:item.lnum = l:err.startPosition.lineNum
|
|
|
|
let l:item.col = l:err.startPosition.offset
|
|
|
|
if has_key(l:err, 'endPosition')
|
|
|
|
let l:item.end_lnum = l:err.endPosition.lineNum
|
|
|
|
let l:item.end_col = l:err.endPosition.offset
|
|
|
|
endif
|
2017-11-16 09:12:08 +00:00
|
|
|
else
|
2017-11-16 10:28:30 +00:00
|
|
|
let l:item.lnum = l:err.lineNum
|
|
|
|
let l:item.col = l:err.sentenceStartColumnNum + 1
|
2017-11-16 09:12:08 +00:00
|
|
|
endif
|
2017-11-16 10:28:30 +00:00
|
|
|
call add(l:output, l:item)
|
2017-11-16 09:12:08 +00:00
|
|
|
endfor
|
2017-11-16 10:28:30 +00:00
|
|
|
return l:output
|
2017-11-16 09:12:08 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('markdown', {
|
|
|
|
\ 'name': 'redpen',
|
|
|
|
\ 'executable': 'redpen',
|
|
|
|
\ 'command': 'redpen -r json %t',
|
|
|
|
\ 'callback': 'ale_linters#markdown#redpen#HandleErrors',
|
|
|
|
\})
|