From c779dbb607b24e6aa8821aae37645b44b6db65de Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Mon, 27 Aug 2018 08:04:25 +0300 Subject: [PATCH] Checker markdown/remark_lint: cleanup. --- autoload/syntastic/preprocess.vim | 43 ++++++++++++++++++++++++ doc/syntastic-checkers.txt | 27 +++++++++++++-- plugin/syntastic.vim | 2 +- syntax_checkers/markdown/remark_lint.vim | 21 ++++++++---- 4 files changed, 84 insertions(+), 9 deletions(-) diff --git a/autoload/syntastic/preprocess.vim b/autoload/syntastic/preprocess.vim index ff7f3a30..1db577ed 100644 --- a/autoload/syntastic/preprocess.vim +++ b/autoload/syntastic/preprocess.vim @@ -388,6 +388,49 @@ function! syntastic#preprocess#rparse(errors) abort " {{{2 return out endfunction " }}}2 +function! syntastic#preprocess#remark_lint(errors) abort " {{{2 + let out = [] + let fname = expand('%', 1) + + for err in a:errors + if err =~# '\m^\f\+$' + let fname = err + + elseif err =~# '\v^\s+\d+:\d+\s+%(warning|error)\s.*remark-lint$' + let parts = matchlist(err, '\v^\s+(\d+):(\d+)\s+([ew])\S+\s+(.{-})\s+(\S+)\s+remark-lint$') + if len(parts) >6 + let line = str2nr(parts[1]) + let col = str2nr(parts[2]) + let type = parts[3] + let message = parts[4] . ' [' . parts[5] . ']' + call add(out, join([fname, type, line, col, message], ':')) + else + call syntastic#log#warn('checker markdown/remark_lint: unrecognized error item ' . string(err)) + endif + + elseif err =~# '\v^\s+\d+:\d+-\d+:\d+\s+%(warning|error)\s.*remark-lint$' + let parts = matchlist(err, '\v^\s+(\d+):(\d+)-(\d+):(\d+)\s+([ew])\S+\s+(.{-})\s+(\S+)\s+remark-lint$') + if len(parts) >8 + let line1 = str2nr(parts[1]) + let col1 = str2nr(parts[2]) + let line2 = str2nr(parts[3]) + let col2 = str2nr(parts[4]) - 1 + let type = parts[5] + let message = parts[6] . ' [' . parts[7] . ']' + if line1 == line2 + call add(out, join([fname, type, line1, col1, col2, message], ':')) + else + call add(out, join([fname, type, line1, col1, message], ':')) + endif + else + call syntastic#log#warn('checker markdown/remark_lint: unrecognized error item ' . string(err)) + endif + endif + endfor + + return out +endfunction " }}}2 + function! syntastic#preprocess#scss_lint(errors) abort " {{{2 let errs = join(a:errors, '') if errs ==# '' diff --git a/doc/syntastic-checkers.txt b/doc/syntastic-checkers.txt index 917efe75..05df3c7f 100644 --- a/doc/syntastic-checkers.txt +++ b/doc/syntastic-checkers.txt @@ -4090,7 +4090,8 @@ The following checkers are available for Markdown (filetype "markdown"): 1. Markdown lint tool.......|syntastic-markdown-mdl| 2. proselint................|syntastic-markdown-proselint| - 3. textlint.................|syntastic-markdown-textlint| + 3. remark-lint..............|syntastic-markdown-remark_lint| + 4. textlint.................|syntastic-markdown-textlint| ------------------------------------------------------------------------------ 1. Markdown lint tool *syntastic-markdown-mdl* @@ -4148,7 +4149,29 @@ See also: |syntastic-asciidoc-proselint|, |syntastic-help-proselint|, |syntastic-text-proselint|, |syntastic-xhtml-proselint|. ------------------------------------------------------------------------------ -3. textlint *syntastic-markdown-textlint* +3. remark-lint *syntastic-markdown-remark_lint* + +Name: remark_lint +Maintainer: Tim Carry + +"remark-lint" is a code style linter for Markdown files. See the project's +page at GitHub for details: + + https://github.com/remarkjs/remark-lint + +Note~ + +Syntastic can't check whether "remark-lint" is installed properly beyond the +existence of an executable named "remark". Please make sure "remark-lint" is +installed and working properly before attempting to use it with syntastic. + +Checker options~ + +This checker is initialised using the "makeprgBuild()" function and thus it +accepts the standard options described at |syntastic-config-makeprg|. + +------------------------------------------------------------------------------ +4. textlint *syntastic-markdown-textlint* Name: textlint Maintainer: LCD 47 diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index 32749d64..1a4a76bd 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -19,7 +19,7 @@ if has('reltime') lockvar! g:_SYNTASTIC_START endif -let g:_SYNTASTIC_VERSION = '3.9.0-9' +let g:_SYNTASTIC_VERSION = '3.9.0-14' lockvar g:_SYNTASTIC_VERSION " Sanity checks {{{1 diff --git a/syntax_checkers/markdown/remark_lint.vim b/syntax_checkers/markdown/remark_lint.vim index 6c642ddb..5b140006 100644 --- a/syntax_checkers/markdown/remark_lint.vim +++ b/syntax_checkers/markdown/remark_lint.vim @@ -20,18 +20,27 @@ let s:save_cpo = &cpo set cpo&vim function! SyntaxCheckers_markdown_remark_lint_GetLocList() dict - let makeprg = self.makeprgBuild({ - \'args_before': '--quiet --no-stdout --no-color' }) + let makeprg = self.makeprgBuild({ 'args_before': '--quiet --no-stdout --no-color' }) let errorformat = - \ '%\s%#%l:%c%\s%#%tarning %m remark-lint,' . - \ '%\s%#%l:%c-%.%#%\s%#%tarning %m remark-lint' + \ '%f:%t:%l:%c:%n:%m,' . + \ '%f:%t:%l:%c:%m' - return SyntasticMake({ + let loclist = SyntasticMake({ \ 'makeprg': makeprg, \ 'errorformat': errorformat, - \ 'defaults': {'bufnr': bufnr('')}, + \ 'preprocess': 'remark_lint', + \ 'subtype': 'Style', \ 'returns': [0] }) + + for e in loclist + if get(e, 'col', 0) && get(e, 'nr', 0) + let e['hl'] = '\%>' . (e['col'] - 1) . 'c\%<' . (e['nr'] + 1) . 'c' + let e['nr'] = 0 + endif + endfor + + return loclist endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({