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

Merge commit 'a39f715c13be3352193ffd9c5b7536b8786eff64' as '.vim/bundle/vim-lsp'
[etc/vim.git] / .vim / bundle / ale / ale_linters / erlang / elvis.vim
1 " Author: Dmitri Vereshchagin <dmitri.vereshchagin@gmail.com>
2 " Description: Elvis linter for Erlang files
3
4 call ale#Set('erlang_elvis_executable', 'elvis')
5
6 function! ale_linters#erlang#elvis#Handle(buffer, lines) abort
7     let l:pattern = '\v:(\d+):[^:]+:(.+)'
8     let l:loclist = []
9
10     for l:match in ale#util#GetMatches(a:lines, l:pattern)
11         call add(l:loclist, {
12         \   'lnum': str2nr(l:match[1]),
13         \   'text': s:AbbreviateMessage(l:match[2]),
14         \   'type': 'W',
15         \   'sub_type': 'style',
16         \})
17     endfor
18
19     return l:loclist
20 endfunction
21
22 function! s:AbbreviateMessage(text) abort
23     let l:pattern = '\v\c^(line \d+ is too long):.*$'
24
25     return substitute(a:text, l:pattern, '\1.', '')
26 endfunction
27
28 function! s:GetCommand(buffer) abort
29     let l:cwd = s:GetCwd(a:buffer)
30
31     let l:file = !empty(l:cwd)
32     \   ? expand('#' . a:buffer . ':p')[len(l:cwd) + 1:]
33     \   : expand('#' . a:buffer . ':.')
34
35     return '%e rock --output-format=parsable ' . ale#Escape(l:file)
36 endfunction
37
38 function! s:GetCwd(buffer) abort
39     let l:markers = ['elvis.config', 'rebar.lock', 'erlang.mk']
40
41     for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
42         for l:marker in l:markers
43             if filereadable(l:path . '/' . l:marker)
44                 return l:path
45             endif
46         endfor
47     endfor
48
49     return ''
50 endfunction
51
52 call ale#linter#Define('erlang', {
53 \   'name': 'elvis',
54 \   'callback': 'ale_linters#erlang#elvis#Handle',
55 \   'executable': {b -> ale#Var(b, 'erlang_elvis_executable')},
56 \   'command': function('s:GetCommand'),
57 \   'cwd': function('s:GetCwd'),
58 \   'lint_file': 1,
59 \})