ale icon indicating copy to clipboard operation
ale copied to clipboard

Add mandoc lint filter for mdoc nroff files

Open fharvell opened this issue 3 years ago • 1 comments

I have created the below mandoc linter and handler. I am not (yet) familiar with Vader but wanted to submit these two files for review and ask for advice on what additional materials needs to be submitted.

ale_linters/nroff/mandoc.vim

" Author: F Harvell https://github.com/fharvell
" Description: mandoc for nroff files

call ale#linter#Define('nroff', {
\   'name': 'mandoc',
\   'executable': 'mandoc',
\   'command': 'mandoc -Tlint %t',
\   'callback': 'ale#handlers#mandoc#HandleMandocFormat'
\})

autoload/ale/handlers/mandoc.vim

" Author: F Harvell https://github.com/fharvell
" Description: Error handling for mandoc lint.

function! ale#handlers#mandoc#HandleMandocFormat(buffer, lines) abort
    let l:pattern = '\v^mandoc: +[^:]*:(\d+):(\d+): +(.*)$'
    let l:output = []
    let l:type = 'I'

    for l:match in ale#util#GetMatches(a:lines, l:pattern)
        if l:match[3] =~? 'ERROR'
            let l:type = 'E'
        elseif l:match[3] =~? 'WARNING'
            let l:type = 'W'
        else
        "elseif l:match[3] =~? 'STYLE'
            let l:type = 'I'
        endif
        call add(l:output, {
        \    'lnum': l:match[1] + 0,
        \    'col': l:match[2] + 0,
        \    'text': l:match[3],
        \    'type': l:type
        \})
    endfor

    return l:output
endfunction

fharvell avatar Feb 28 '22 01:02 fharvell

This is a very simple example of adding a new linter. It is easy to see what needs to be added:

  • https://github.com/dense-analysis/ale/pull/3950/files

In specific:

  • Instead of hardcoding the executable and command in the linter definition create functions in the handler to generate those from configuration variables and set some defaults. See ale_linters/avra/avra.vim
  • Create a linter test. See test/linter/test_avra_avra.vader
  • Create a handler test. See test/handler/test_avra_handler.vader
  • Update supported-tools.md, doc/ale.txt, doc/ale-supported-languages-and-tools.txt, and ale-nroff.txt with documentation on the new linter. Note that sort order of the tools is important. Make sure is alphabetical on all files.

hsanson avatar Mar 01 '22 00:03 hsanson