]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/v/v.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 / v / v.vim
1 " Author: fiatjaf <fiatjaf@alhur.es>
2 " Description: v build for V files
3
4 call ale#Set('v_v_executable', 'v')
5 call ale#Set('v_v_options', '')
6
7 function! ale_linters#v#v#Handler(buffer, lines) abort
8     let l:dir = expand('#' . a:buffer . ':p:h')
9     let l:output = []
10
11     " Matches patterns like the following:
12     "
13     " ./const.v:4:3: warning: const names cannot contain uppercase letters, use snake_case instead
14     "     2 |
15     "     3 | const (
16     "     4 |   BUTTON_TEXT = 'OK'
17     "       |   ~~~~~~~~~~~
18     "     5 | )
19     " ./main.v:4:8: warning: module 'os' is imported but never used
20     "     2 |
21     "     3 | import ui
22     "     4 | import os
23     "       |        ~~
24     "     5 |
25     "     6 | const (
26     " ./main.v:20:10: error: undefined ident: `win_widt`
27     "    18 |     mut app := &App{}
28     "    19 |     app.window = ui.window({
29     "    20 |         width: win_widt
30     "       |                ~~~~~~~~
31     "    21 |         height: win_height
32     "    22 |         title: 'Counter'
33     let l:current = {}
34
35     for l:line in a:lines
36         " matches basic error description
37         let l:match = matchlist(l:line,
38         \ '\([^:]\+\):\([^:]\+\):\([^:]\+\): \([^:]\+\): \(.*\)')
39
40         if !empty(l:match)
41             let l:current = {
42             \   'filename': ale#path#GetAbsPath(l:dir, l:match[1]),
43             \   'lnum': l:match[2] + 0,
44             \   'col': l:match[3] + 0,
45             \   'text': l:match[5],
46             \   'type': l:match[4] is# 'error' ? 'E' : 'W',
47             \}
48             call add(l:output, l:current)
49             continue
50         endif
51
52         " try to get information about the ending column
53         let l:tildematch = matchstr(l:line, '\~\+')
54
55         if !empty(l:tildematch)
56             let l:current['end_col'] = l:current['col'] + len(l:tildematch)
57         endif
58     endfor
59
60     return l:output
61 endfunction
62
63 call ale#linter#Define('v', {
64 \   'name': 'v',
65 \   'executable': {b -> ale#Var(b, 'v_v_executable')},
66 \   'command': {b ->
67 \       '%e' . ale#Pad(ale#Var(b, 'v_v_options'))
68 \       . ' . -o /tmp/vim-ale-v'
69 \   },
70 \   'output_stream': 'stderr',
71 \   'callback': 'ale_linters#v#v#Handler',
72 \   'lint_file': 1,
73 \})