2018-07-24 05:05:44 -04:00
|
|
|
scriptencoding utf-8
|
2018-03-22 06:40:47 -04:00
|
|
|
" Author rhysd https://rhysd.github.io/, Dirk Roorda (dirkroorda), Adrián González Rus (@adrigzr)
|
2017-10-19 04:22:47 -04:00
|
|
|
" Description: remark-lint for Markdown files
|
2018-07-10 09:05:49 -04:00
|
|
|
call ale#Set('markdown_remark_lint_executable', 'remark')
|
|
|
|
call ale#Set('markdown_remark_lint_use_global', get(g:, 'ale_use_global_executables', 0))
|
|
|
|
call ale#Set('markdown_remark_lint_options', '')
|
|
|
|
|
|
|
|
function! ale_linters#markdown#remark_lint#GetCommand(buffer) abort
|
|
|
|
let l:options = ale#Var(a:buffer, 'markdown_remark_lint_options')
|
|
|
|
|
2018-08-02 18:44:12 -04:00
|
|
|
return '%e' . ale#Pad(l:options) . ' --no-stdout --no-color'
|
2018-07-10 09:05:49 -04:00
|
|
|
endfunction
|
2017-10-19 04:22:47 -04:00
|
|
|
|
|
|
|
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'
|
2018-03-22 06:40:47 -04:00
|
|
|
" 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\) \(.\+\)$'
|
2017-10-19 04:22:47 -04:00
|
|
|
let l:output = []
|
|
|
|
|
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2018-03-22 06:40:47 -04:00
|
|
|
let l:item = {
|
2017-10-19 04:22:47 -04:00
|
|
|
\ 'lnum': l:match[1] + 0,
|
|
|
|
\ 'col': l:match[2] + 0,
|
2018-03-22 06:40:47 -04:00
|
|
|
\ 'type': l:match[6] is# 'error' ? 'E' : 'W',
|
|
|
|
\ 'text': l:match[7],
|
|
|
|
\}
|
2018-09-04 11:51:18 -04:00
|
|
|
|
2018-03-22 06:40:47 -04:00
|
|
|
if l:match[3] isnot# ''
|
|
|
|
let l:item.end_lnum = l:match[4] + 0
|
|
|
|
let l:item.end_col = l:match[5] + 0
|
|
|
|
endif
|
2018-09-04 11:51:18 -04:00
|
|
|
|
2018-03-22 06:40:47 -04:00
|
|
|
call add(l:output, l:item)
|
2017-10-19 04:22:47 -04:00
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('markdown', {
|
2018-07-24 05:05:44 -04:00
|
|
|
\ 'name': 'remark_lint',
|
|
|
|
\ 'aliases': ['remark-lint'],
|
2018-08-02 18:44:12 -04:00
|
|
|
\ 'executable_callback': ale#node#FindExecutableFunc('markdown_remark_lint', [
|
|
|
|
\ 'node_modules/.bin/remark',
|
|
|
|
\ ]),
|
2018-07-10 09:05:49 -04:00
|
|
|
\ 'command_callback': 'ale_linters#markdown#remark_lint#GetCommand',
|
2017-10-19 04:22:47 -04:00
|
|
|
\ 'callback': 'ale_linters#markdown#remark_lint#Handle',
|
|
|
|
\ 'output_stream': 'stderr',
|
|
|
|
\})
|