ale/ale_linters/vala/vala_lint.vim

67 lines
2.1 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.
call ale#Set('vala_vala_lint_config_filename', 'vala-lint.conf')
2021-01-14 00:52:36 +00:00
call ale#Set('vala_vala_lint_executable', 'io.elementary.vala-lint')
function! ale_linters#vala#vala_lint#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'vala_vala_lint_executable')
endfunction
2021-01-02 06:42:38 +00:00
function! ale_linters#vala#vala_lint#GetCommand(buffer) abort
2021-01-14 00:52:36 +00:00
let l:command = ale_linters#vala#vala_lint#GetExecutable(a:buffer)
let l:config_filename = ale#Var(a:buffer, 'vala_vala_lint_config_filename')
let l:config_path = ale#path#FindNearestFile(a:buffer, l:config_filename)
2021-01-05 08:51:59 +00:00
if !empty(l:config_path)
let l:command .= ' -c ' . l:config_path
endif
return l:command . ' %s'
2021-01-02 06:42:38 +00:00
endfunction
function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort
2021-01-04 07:00:30 +00:00
let l:pattern = '^\s*\(\d\+\)\.\(\d\+\)\s\+\(error\|warn\)\s\+\(.\+\)\s\([A-Za-z0-9_\-]\+\)'
2021-01-02 06:42:38 +00:00
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, '\e\[[0-9;]\+[mK]', '', 'g')
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
2021-01-04 07:00:30 +00:00
let l:refined_type = l:match[3] is# 'warn' ? 'W' : 'E'
let l:cleaned_text = substitute(l:match[4], '^\s*\(.\{-}\)\s*$', '\1', '')
2021-01-02 07:48:54 +00:00
let l:lnum = l:match[1] + 0
let l:column = l:match[2] + 0
2021-01-04 07:00:30 +00:00
let l:type = l:refined_type
let l:text = l:cleaned_text
2021-01-02 07:48:54 +00:00
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', {
2021-01-22 15:20:11 +00:00
\ 'name': 'vala_lint',
2021-01-02 06:52:10 +00:00
\ 'output_stream': 'stdout',
2021-01-14 00:52:36 +00:00
\ 'executable': function('ale_linters#vala#vala_lint#GetExecutable'),
2021-01-02 06:42:38 +00:00
\ 'command': function('ale_linters#vala#vala_lint#GetCommand'),
\ 'callback': 'ale_linters#vala#vala_lint#Handle',
\ 'lint_file': 1,
\})