]> git.madduck.net Git - etc/vim.git/blob - ale_linters/vim/vint.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:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / ale_linters / vim / vint.vim
1 " Author: w0rp <devw0rp@gmail.com>, KabbAmine <amine.kabb@gmail.com>
2 " Description: This file adds support for checking Vim code with Vint.
3
4 " This flag can be used to change enable/disable style issues.
5 call ale#Set('vim_vint_show_style_issues', 1)
6 call ale#Set('vim_vint_executable', 'vint')
7 let s:enable_neovim = has('nvim') ? ' --enable-neovim' : ''
8 let s:format = '-f "{file_path}:{line_number}:{column_number}: {severity}: {policy_name} - {description} (see {reference})"'
9
10 function! ale_linters#vim#vint#GetCommand(buffer, version) abort
11     let l:can_use_no_color_flag = empty(a:version)
12     \   || ale#semver#GTE(a:version, [0, 3, 7])
13
14     let l:warning_flag = ale#Var(a:buffer, 'vim_vint_show_style_issues') ? '-s' : '-w'
15
16     " Use the --stdin-display-name argument if supported, temp file otherwise.
17     let l:stdin_or_temp = ale#semver#GTE(a:version, [0, 4, 0])
18     \   ? ' --stdin-display-name %s -'
19     \   : ' %t'
20
21     return '%e'
22     \   . ' ' . l:warning_flag
23     \   . (l:can_use_no_color_flag ? ' --no-color' : '')
24     \   . s:enable_neovim
25     \   . ' ' . s:format
26     \   . l:stdin_or_temp
27 endfunction
28
29 let s:word_regex_list = [
30 \   '\v^Undefined variable: ([^ ]+)',
31 \   '\v^Make the scope explicit like ...([^ ]+). ',
32 \   '\v^.*start with a capital or contain a colon: ([^ ]+)',
33 \   '\v.*instead of .(\=[=~]).',
34 \]
35
36 function! ale_linters#vim#vint#Handle(buffer, lines) abort
37     let l:loclist = ale#handlers#gcc#HandleGCCFormat(a:buffer, a:lines)
38
39     for l:item in l:loclist
40         let l:match = []
41
42         for l:regex in s:word_regex_list
43             let l:match = matchlist(l:item.text, l:regex)
44
45             if !empty(l:match)
46                 let l:item.end_col = l:item.col + len(l:match[1]) - 1
47                 break
48             endif
49         endfor
50     endfor
51
52     return l:loclist
53 endfunction
54
55 call ale#linter#Define('vim', {
56 \   'name': 'vint',
57 \   'executable': {buffer -> ale#Var(buffer, 'vim_vint_executable')},
58 \   'command': {buffer -> ale#semver#RunWithVersionCheck(
59 \       buffer,
60 \       ale#Var(buffer, 'vim_vint_executable'),
61 \       '%e --version',
62 \       function('ale_linters#vim#vint#GetCommand'),
63 \   )},
64 \   'callback': 'ale_linters#vim#vint#Handle',
65 \})