2018-03-31 10:55:20 -04:00
|
|
|
" Author: Nick Yamane <nick.diego@gmail.com>
|
|
|
|
" Description: gitlint for git commit message files
|
|
|
|
|
2018-08-25 12:13:42 -04:00
|
|
|
call ale#Set('gitcommit_gitlint_executable', 'gitlint')
|
|
|
|
call ale#Set('gitcommit_gitlint_options', '')
|
|
|
|
call ale#Set('gitcommit_gitlint_use_global', get(g:, 'ale_use_global_executables', 0))
|
2018-03-31 10:55:20 -04:00
|
|
|
|
|
|
|
function! ale_linters#gitcommit#gitlint#GetExecutable(buffer) abort
|
|
|
|
return ale#python#FindExecutable(a:buffer, 'gitcommit_gitlint', ['gitlint'])
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#gitcommit#gitlint#GetCommand(buffer) abort
|
|
|
|
let l:options = ale#Var(a:buffer, 'gitcommit_gitlint_options')
|
|
|
|
|
2018-08-25 12:13:42 -04:00
|
|
|
return '%e' . ale#Pad(l:options) . ' lint'
|
|
|
|
endfunction
|
2018-03-31 10:55:20 -04:00
|
|
|
|
|
|
|
function! ale_linters#gitcommit#gitlint#Handle(buffer, lines) abort
|
|
|
|
" Matches patterns line the following:
|
|
|
|
let l:pattern = '\v^(\d+): (\w+) (.*)$'
|
|
|
|
let l:output = []
|
|
|
|
|
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
|
|
|
let l:code = l:match[2]
|
|
|
|
|
2018-09-24 20:40:17 -04:00
|
|
|
if !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
|
|
|
|
if l:code is# 'T2' || l:code is# 'B2'
|
|
|
|
continue
|
|
|
|
endif
|
2018-06-14 06:31:12 -04:00
|
|
|
endif
|
|
|
|
|
2018-03-31 10:55:20 -04:00
|
|
|
let l:item = {
|
|
|
|
\ 'lnum': l:match[1] + 0,
|
|
|
|
\ 'text': l:match[3],
|
|
|
|
\ 'code': l:code,
|
|
|
|
\ 'type': 'E',
|
|
|
|
\}
|
|
|
|
|
|
|
|
call add(l:output, l:item)
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('gitcommit', {
|
|
|
|
\ 'name': 'gitlint',
|
|
|
|
\ 'output_stream': 'stderr',
|
|
|
|
\ 'executable_callback': 'ale_linters#gitcommit#gitlint#GetExecutable',
|
|
|
|
\ 'command_callback': 'ale_linters#gitcommit#gitlint#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#gitcommit#gitlint#Handle',
|
|
|
|
\})
|