]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/vala/vala_lint.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / ale_linters / vala / vala_lint.vim
1 " Author: Atsuya Takagi <asoftonight@gmail.com>
2 " Description: A linter for Vala using Vala-Lint.
3
4 call ale#Set('vala_vala_lint_config_filename', 'vala-lint.conf')
5 call ale#Set('vala_vala_lint_executable', 'io.elementary.vala-lint')
6
7 function! ale_linters#vala#vala_lint#GetExecutable(buffer) abort
8     return ale#Var(a:buffer, 'vala_vala_lint_executable')
9 endfunction
10
11 function! ale_linters#vala#vala_lint#GetCommand(buffer) abort
12     let l:command = ale_linters#vala#vala_lint#GetExecutable(a:buffer)
13
14     let l:config_filename = ale#Var(a:buffer, 'vala_vala_lint_config_filename')
15     let l:config_path = ale#path#FindNearestFile(a:buffer, l:config_filename)
16
17     if !empty(l:config_path)
18         let l:command .= ' -c ' . l:config_path
19     endif
20
21     return l:command . ' %s'
22 endfunction
23
24 function! ale_linters#vala#vala_lint#Handle(buffer, lines) abort
25     let l:pattern = '^\s*\(\d\+\)\.\(\d\+\)\s\+\(error\|warn\)\s\+\(.\+\)\s\([A-Za-z0-9_\-]\+\)'
26     let l:output = []
27
28     for l:line in a:lines
29         " remove color escape sequences since vala-lint doesn't support
30         " output without colors
31         let l:cleaned_line = substitute(l:line, '\e\[[0-9;]\+[mK]', '', 'g')
32         let l:match = matchlist(l:cleaned_line, l:pattern)
33
34         if len(l:match) == 0
35             continue
36         endif
37
38         let l:refined_type = l:match[3] is# 'warn' ? 'W' : 'E'
39         let l:cleaned_text = substitute(l:match[4], '^\s*\(.\{-}\)\s*$', '\1', '')
40
41         let l:lnum = l:match[1] + 0
42         let l:column = l:match[2] + 0
43         let l:type = l:refined_type
44         let l:text = l:cleaned_text
45         let l:code = l:match[5]
46
47         call add(l:output, {
48         \   'lnum': l:lnum,
49         \   'col': l:column,
50         \   'text': l:text,
51         \   'type': l:type,
52         \   'code': l:code,
53         \})
54     endfor
55
56     return l:output
57 endfunction
58
59 call ale#linter#Define('vala', {
60 \   'name': 'vala_lint',
61 \   'output_stream': 'stdout',
62 \   'executable': function('ale_linters#vala#vala_lint#GetExecutable'),
63 \   'command': function('ale_linters#vala#vala_lint#GetCommand'),
64 \   'callback': 'ale_linters#vala#vala_lint#Handle',
65 \   'lint_file': 1,
66 \})