summaryrefslogtreecommitdiff
path: root/ale_linters/erlang/elvis.vim
diff options
context:
space:
mode:
authorDmitri Vereshchagin <dmitri.vereshchagin@gmail.com>2019-09-01 17:36:40 +0300
committerDmitri Vereshchagin <dmitri.vereshchagin@gmail.com>2020-09-06 12:40:28 +0300
commit49718e0ec6eb4b9068049048c9373167c19257c9 (patch)
tree3df86c81d31ccedd77dddd68b1fcdb551bb55958 /ale_linters/erlang/elvis.vim
parent5bc49d204782617e01da65d83c0d9700a1b0a72f (diff)
downloadale-49718e0ec6eb4b9068049048c9373167c19257c9.zip
Add Elvis handler for Erlang
[Elvis][1] is an Erlang style reviewer. [1]: https://github.com/inaka/elvis
Diffstat (limited to 'ale_linters/erlang/elvis.vim')
-rw-r--r--ale_linters/erlang/elvis.vim39
1 files changed, 39 insertions, 0 deletions
diff --git a/ale_linters/erlang/elvis.vim b/ale_linters/erlang/elvis.vim
new file mode 100644
index 00000000..31dea3dd
--- /dev/null
+++ b/ale_linters/erlang/elvis.vim
@@ -0,0 +1,39 @@
+" Author: Dmitri Vereshchagin <dmitri.vereshchagin@gmail.com>
+" Description: Elvis linter for Erlang files
+
+call ale#Set('erlang_elvis_executable', 'elvis')
+
+function! ale_linters#erlang#elvis#Handle(buffer, lines) abort
+ let l:pattern = '\v:(\d+):[^:]+:(.+)'
+ let l:loclist = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ call add(l:loclist, {
+ \ 'lnum': str2nr(l:match[1]),
+ \ 'text': s:AbbreviateMessage(l:match[2]),
+ \ 'type': 'W',
+ \})
+ endfor
+
+ return l:loclist
+endfunction
+
+function! s:AbbreviateMessage(text) abort
+ let l:pattern = '\v\c^(line \d+ is too long):.*$'
+
+ return substitute(a:text, l:pattern, '\1.', '')
+endfunction
+
+function! s:GetCommand(buffer) abort
+ let l:file = ale#Escape(expand('#' . a:buffer . ':.'))
+
+ return '%e rock --output-format=parsable ' . l:file
+endfunction
+
+call ale#linter#Define('erlang', {
+\ 'name': 'elvis',
+\ 'callback': 'ale_linters#erlang#elvis#Handle',
+\ 'executable': {b -> ale#Var(b, 'erlang_elvis_executable')},
+\ 'command': function('s:GetCommand'),
+\ 'lint_file': 1,
+\})