ale/ale_linters/vala/vala_lint.vim

50 lines
1.5 KiB
VimL
Raw Normal View History

2021-01-02 06:42:38 +00:00
" Author: Atsuya Takagi <asoftonight@gmail.com>
" Description: A linter for Vala using Vala-Lint.
function! ale_linters#vala#vala_lint#GetCommand(buffer) abort
return 'io.elementary.vala-lint %s'
2021-01-02 06:42:38 +00:00
endfunction
function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort
let l:pattern = '^\s*\(\d\+\)\.\(\d\+\)\s\+\(\w\+\)\s\+\(.\+\)\s\([A-Za-z0-9_\-]\+\)'
let l:output = []
2021-01-02 07:48:54 +00:00
for l:line in a:lines
" remove color escape sequences since vala-lint doesn't support
" output without colors
let l:cleaned_line = substitute(l:line, '\x1b\[[0-9;]*m', '', 'g')
execute 'echo l:line'
execute 'echo l:cleaned_line'
2021-01-02 07:54:06 +00:00
let l:match = matchlist(l:cleaned_line, l:pattern)
2021-01-02 07:48:54 +00:00
if len(l:match) == 0
continue
endif
let l:lnum = l:match[1] + 0
let l:column = l:match[2] + 0
let l:type = 'E'
let l:text = substitute(l:match[4], '^\s*\(.\{-}\)\s*$', '\1', '')
let l:code = l:match[5]
call add(l:output, {
\ 'lnum': l:lnum,
\ 'col': l:column,
\ 'text': l:text,
\ 'type': l:type,
\ 'code': l:code,
\})
endfor
2021-01-02 06:42:38 +00:00
return l:output
endfunction
call ale#linter#Define('vala', {
\ 'name': 'vala-lint',
2021-01-02 06:52:10 +00:00
\ 'output_stream': 'stdout',
2021-01-02 06:42:38 +00:00
\ 'executable': 'io.elementary.vala-lint',
\ 'command': function('ale_linters#vala#vala_lint#GetCommand'),
\ 'callback': 'ale_linters#vala#vala_lint#Handle',
\ 'lint_file': 1,
\})