diff options
author | Nick Diego Yamane <nick.diego@gmail.com> | 2017-12-20 06:10:07 -0400 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2017-12-20 10:10:07 +0000 |
commit | d4b43d23f4a9f277a482fdad4ea3a3e951d80eab (patch) | |
tree | 0d66493a39ced077df4c978b0f1b1f3f30db80ba /ale_linters/gitcommit/gitlint.vim | |
parent | 1568bf81281507aaaa8c71af85e244e94bd2924c (diff) | |
download | ale-d4b43d23f4a9f277a482fdad4ea3a3e951d80eab.zip |
Add support for linting git commit message files (#1233)
Diffstat (limited to 'ale_linters/gitcommit/gitlint.vim')
-rw-r--r-- | ale_linters/gitcommit/gitlint.vim | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/ale_linters/gitcommit/gitlint.vim b/ale_linters/gitcommit/gitlint.vim new file mode 100644 index 00000000..991d5a1a --- /dev/null +++ b/ale_linters/gitcommit/gitlint.vim @@ -0,0 +1,51 @@ +" Author: Nick Yamane <nick.diego@gmail.com> +" Description: gitlint for git commit message files + +let g:ale_gitcommit_gitlint_executable = +\ get(g:, 'ale_gitcommit_gitlint_executable', 'gitlint') +let g:ale_gitcommit_gitlint_options = get(g:, 'ale_gitcommit_gitlint_options', '') +let g:ale_gitcommit_gitlint_use_global = get(g:, 'ale_gitcommit_gitlint_use_global', 0) + + +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') + let l:executable = ale_linters#gitcommit#gitlint#GetExecutable(a:buffer) + return ale#Escape(l:executable) + \ . (!empty(l:options) ? ' ' . l:options : '') + \ . ' lint' +endfunction + + +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] + + let l:item = { + \ 'lnum': l:match[1] + 0, + \ 'text': l:code . ': ' . l:match[3], + \ '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', +\}) + |