File: selene.vim

package info (click to toggle)
vim-ale 4.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,764 kB
  • sloc: sh: 499; python: 311; perl: 31; makefile: 4; xml: 4; javascript: 1
file content (46 lines) | stat: -rw-r--r-- 1,588 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
call ale#Set('lua_selene_executable', 'selene')
call ale#Set('lua_selene_options', '')

function! ale_linters#lua#selene#GetCommand(buffer) abort
    return '%e' . ale#Pad(ale#Var(a:buffer, 'lua_selene_options'))
    \   . ' --display-style=json -'
endfunction

function! ale_linters#lua#selene#Handle(buffer, lines) abort
    let l:output = []

    for l:line in a:lines
        " as of version 0.17.0, selene has no way to suppress summary
        " information when outputting json, so stop processing when we hit it
        " (PR for this here: https://github.com/Kampfkarren/selene/pull/356)
        if l:line is# 'Results:'
            break
        endif

        let l:json = json_decode(l:line)
        let l:lint = {
        \   'lnum': l:json.primary_label.span.start_line + 1,
        \   'end_lnum': l:json.primary_label.span.end_line + 1,
        \   'col': l:json.primary_label.span.start_column + 1,
        \   'end_col': l:json.primary_label.span.end_column,
        \   'text': l:json.message,
        \   'code': l:json.code,
        \   'type': l:json.severity is# 'Warning' ? 'W' : 'E',
        \}

        if has_key(l:json, 'notes') && len(l:json.notes) > 0
            let l:lint.detail = l:lint.text . "\n\n" . join(l:json.notes, "\n")
        endif

        call add(l:output, l:lint)
    endfor

    return l:output
endfunction

call ale#linter#Define('lua', {
\   'name': 'selene',
\   'executable': {b -> ale#Var(b, 'lua_selene_executable')},
\   'command': function('ale_linters#lua#selene#GetCommand'),
\   'callback': 'ale_linters#lua#selene#Handle',
\})