dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.38k stars 1.42k forks source link

Handle ranges for the remark linter #1207

Closed dirkroorda closed 6 years ago

dirkroorda commented 6 years ago

Information

VIM version: VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Oct 5 2017 04:42:50). Operating System: macOS High Sierra

:ALEInfo

Current Filetype: markdown Available Linters: ['mdl', 'proselint', 'redpen', 'remark-lint', 'vale', 'write-good'] Enabled Linters: ['mdl', 'proselint', 'redpen', 'remark-lint', 'vale', 'write-good'] Linter Variables:

Global Variables:

let g:ale_echo_cursor = 1 let g:ale_echo_msg_error_str = 'Error' let g:ale_echo_msg_format = '%code: %%s' let g:ale_echo_msg_warning_str = 'Warning' let g:ale_enabled = 1 let g:ale_fix_on_save = 0 let g:ale_fixers = {'markdown': ['prettier'], 'javascript': ['prettier'], 'python': ['yapf']} let g:ale_keep_list_window_open = 0 let g:ale_lint_delay = 200 let g:ale_lint_on_enter = 1 let g:ale_lint_on_save = 1 let g:ale_lint_on_text_changed = 'always' let g:ale_linter_aliases = {} let g:ale_linters = {} let g:ale_open_list = 0 let g:ale_set_highlights = 1 let g:ale_set_loclist = 1 let g:ale_set_quickfix = 0 let g:ale_set_signs = 1 let g:ale_sign_column_always = 0 let g:ale_sign_error = '>>' let g:ale_sign_offset = 1000000 let g:ale_sign_warning = '--' let g:ale_statusline_format = ['%d error(s)', '%d warning(s)', 'OK'] let g:ale_warn_about_trailing_whitespace = 1 Command History:

(executable check - failure) mdl (executable check - failure) proselint (executable check - failure) redpen (executable check - success) remark (started) ['/bin/bash', '-c', 'remark --no-stdout --no-color ''/Users/dirk/github/Dans-labs/dariah/docs/componentsttest.md'''] (executable check - failure) vale (executable check - failure) write-good (executable check - failure) mdl (executable check - failure) proselint (executable check - failure) redpen (finished - exit code 0) ['/bin/bash', '-c', 'remark --no-stdout --no-color ''/Users/dirk/github/Dans-labs/dariah/docs/componentsttest.md''']

<<>> componentsttest.md 9:16-9:28 warning Emphasis should use * as a marker emphasis-marker remark-lint 9:52-9:59 warning Emphasis should use * as a marker emphasis-marker remark-lint 17:1-20:32 warning Marker style should be - unordered-list-marker-style remark-lint 20:32-21:1 warning Missing new line after list item list-item-spacing remark-lint 21:1-26:26 warning Marker style should be - unordered-list-marker-style remark-lint

⚠ 5 warnings <<>>

(executable check - failure) vale (executable check - failure) write-good

What went wrong

None of the warnings ended up as signs in the gutter.

Reproducing the bug

I have a file .remarkrc.yaml in my home directory with the contents:

plugins:
  - preset-lint-markdown-style-guide
  - frontmatter
settings:
  verbose: true
  quote: "'"
  quoteSmart: true
  preferUnquoted: true

The markdown file to test this on, can be as simple as

*test*

Cause

In ale-linters/markdown/remark_lint.vim the pattern that is used to extract the line/char position does not match ranges, like 9:3-10:5, only single places.

Solution

Adapt the pattern, like so:

for l:match in ale#util#GetMatches(a:lines, l:pattern)
        let l:item = {
        \   'lnum': l:match[1] + 0,
        \   'col': l:match[2] + 0,
        \   'type': l:match[6] is# 'error' ? 'E' : 'W',
        \   '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

I have tested this, and it works. (I have zero experience in vim-scripting, but I saw how apiblueprint/drafter.vim deals with ranges, and merged that in).

dirkroorda commented 6 years ago

I see now that in my post I left out the adapted pattern, just before get matches. I will add that as soon I’m behind a proper computer.

dirkroorda commented 6 years ago

the whole of my remark_lint.vim

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'
    let l:pattern = '^ \+\(\d\+\):\(\d\+\)\(-\(\d\+\):\(\d\+\)\)\?  \(warning\|error\)  \(.\+\)$'
    let l:output = []

    for l:match in ale#util#GetMatches(a:lines, l:pattern)
        let l:item = {
        \   'lnum': l:match[1] + 0,
        \   'col': l:match[2] + 0,
        \   'type': l:match[6] is# 'error' ? 'E' : 'W',
        \   '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)
        \   'lnum': l:match[1] + 0,
        \   'col': l:match[2] + 0,
        \   'end_lnum': l:match[4] + 0,
        \   'end_col': l:match[5] + 0,
        \   'type': l:match[6] is# 'error' ? 'E' : 'W',
        \   'text': l:match[7],
        \})
    endfor

    return l:output
endfunction

call ale#linter#Define('markdown', {
\   'name': 'remark-lint',
\   'executable': 'remark',
\   'command': 'remark --no-stdout --no-color %s',
\   'callback': 'ale_linters#markdown#remark_lint#Handle',
\   'lint_file': 1,
\   'output_stream': 'stderr',
\})
dirkroorda commented 6 years ago

By the way, I really like and admire the way you have done ALE. I have now three linter/formatters working, for Python, ES6, and Markdown. The fact that you install them first outside vim, and then get them working inside vim with zero config is aLesome!

adrigzr commented 6 years ago

Hi!

Will there be any fix soon for this issue? I can open a PR if necessary :)

Thanks!

w0rp commented 6 years ago

Yeah, open a pull request with some tests for the changes to how errors are handled, and I'll have a look.

adrigzr commented 6 years ago

PR added (#1441) :)