]> git.madduck.net Git - etc/vim.git/blob - ale_linters/gitcommit/gitlint.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 / gitcommit / gitlint.vim
1 " Author: Nick Yamane <nick.diego@gmail.com>
2 " Description: gitlint for git commit message files
3
4 call ale#Set('gitcommit_gitlint_executable', 'gitlint')
5 call ale#Set('gitcommit_gitlint_options', '')
6 call ale#Set('gitcommit_gitlint_use_global', get(g:, 'ale_use_global_executables', 0))
7
8 function! ale_linters#gitcommit#gitlint#GetExecutable(buffer) abort
9     return ale#python#FindExecutable(a:buffer, 'gitcommit_gitlint', ['gitlint'])
10 endfunction
11
12 function! ale_linters#gitcommit#gitlint#GetCommand(buffer) abort
13     let l:options = ale#Var(a:buffer, 'gitcommit_gitlint_options')
14
15     return '%e' . ale#Pad(l:options) . ' lint'
16 endfunction
17
18 function! ale_linters#gitcommit#gitlint#Handle(buffer, lines) abort
19     " Matches patterns line the following:
20     let l:pattern = '\v^(\d+): (\w+) (.*)$'
21     let l:output = []
22
23     for l:match in ale#util#GetMatches(a:lines, l:pattern)
24         let l:code = l:match[2]
25
26         if !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
27             if l:code is# 'T2' || l:code is# 'B2'
28                 continue
29             endif
30         endif
31
32         let l:item = {
33         \   'lnum': l:match[1] + 0,
34         \   'text': l:match[3],
35         \   'code': l:code,
36         \   'type': 'E',
37         \}
38
39         call add(l:output, l:item)
40     endfor
41
42     return l:output
43 endfunction
44
45 call ale#linter#Define('gitcommit', {
46 \   'name': 'gitlint',
47 \   'output_stream': 'stderr',
48 \   'executable': function('ale_linters#gitcommit#gitlint#GetExecutable'),
49 \   'command': function('ale_linters#gitcommit#gitlint#GetCommand'),
50 \   'callback': 'ale_linters#gitcommit#gitlint#Handle',
51 \})