summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2020-11-21 15:56:50 +0000
committerGitHub <noreply@github.com>2020-11-21 15:56:50 +0000
commit8e28de142affcc60b2b860603d299c44b43a4040 (patch)
tree7b3868ebe839b653a2f51fe341156c897ca490a2
parentdf3163223f26830782400c453d387394ef561682 (diff)
parent49718e0ec6eb4b9068049048c9373167c19257c9 (diff)
downloadale-8e28de142affcc60b2b860603d299c44b43a4040.zip
Merge pull request #3292 from dmitrivereshchagin/add-elvis-handler-for-erlang
Add Elvis handler for Erlang
-rw-r--r--ale_linters/erlang/elvis.vim39
-rw-r--r--doc/ale-erlang.txt12
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/command_callback/test_erlang_elvis_command_callback.vader16
-rw-r--r--test/handler/test_erlang_elvis_handler.vader37
7 files changed, 107 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,
+\})
diff --git a/doc/ale-erlang.txt b/doc/ale-erlang.txt
index 59993a99..38762f08 100644
--- a/doc/ale-erlang.txt
+++ b/doc/ale-erlang.txt
@@ -31,6 +31,18 @@ g:ale_erlang_dialyzer_rebar3_profile *g:ale_erlang_dialyzer_rebar3_profile*
This variable can be changed to specify the profile that is used to
run dialyzer with rebar3.
+
+-------------------------------------------------------------------------------
+elvis *ale-erlang-elvis*
+
+g:ale_erlang_elvis_executable *g:ale_erlang_elvis_executable*
+ *b:ale_erlang_elvis_executable*
+ Type: |String|
+ Default: `'elvis'`
+
+ This variable can be changed to specify the elvis executable.
+
+
-------------------------------------------------------------------------------
erlc *ale-erlang-erlc*
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 4f3afd85..ba96c37c 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -140,6 +140,7 @@ Notes:
* `erubis`
* `ruumba`
* Erlang
+ * `elvis`!!
* `erlc`
* `SyntaxErl`
* Fish
diff --git a/doc/ale.txt b/doc/ale.txt
index 20baf355..fdd95ace 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2631,6 +2631,7 @@ documented in additional help files.
elm-make..............................|ale-elm-elm-make|
erlang..................................|ale-erlang-options|
dialyzer..............................|ale-erlang-dialyzer|
+ elvis.................................|ale-erlang-elvis|
erlc..................................|ale-erlang-erlc|
syntaxerl.............................|ale-erlang-syntaxerl|
eruby...................................|ale-eruby-options|
diff --git a/supported-tools.md b/supported-tools.md
index 49460892..cf7ee25a 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -149,6 +149,7 @@ formatting.
* [erubis](https://github.com/kwatch/erubis)
* [ruumba](https://github.com/ericqweinstein/ruumba)
* Erlang
+ * [elvis](https://github.com/inaka/elvis) :floppy_disk:
* [erlc](http://erlang.org/doc/man/erlc.html)
* [SyntaxErl](https://github.com/ten0s/syntaxerl)
* Fish
diff --git a/test/command_callback/test_erlang_elvis_command_callback.vader b/test/command_callback/test_erlang_elvis_command_callback.vader
new file mode 100644
index 00000000..4aab49d6
--- /dev/null
+++ b/test/command_callback/test_erlang_elvis_command_callback.vader
@@ -0,0 +1,16 @@
+Before:
+ let b:file = fnamemodify(bufname(''), ':.')
+ call ale#assert#SetUpLinterTest('erlang', 'elvis')
+
+After:
+ call ale#assert#TearDownLinterTest()
+
+Execute(Default command should be correct):
+ AssertLinter 'elvis',
+ \ ale#Escape('elvis') . ' rock --output-format=parsable ' . ale#Escape(b:file)
+
+Execute(Executable should be configurable):
+ let b:ale_erlang_elvis_executable = '/path/to/elvis'
+
+ AssertLinter '/path/to/elvis',
+ \ ale#Escape('/path/to/elvis') . ' rock --output-format=parsable ' . ale#Escape(b:file)
diff --git a/test/handler/test_erlang_elvis_handler.vader b/test/handler/test_erlang_elvis_handler.vader
new file mode 100644
index 00000000..365376c8
--- /dev/null
+++ b/test/handler/test_erlang_elvis_handler.vader
@@ -0,0 +1,37 @@
+Before:
+ runtime ale_linters/erlang/elvis.vim
+
+After:
+ call ale#linter#Reset()
+
+Execute(Warning messages should be handled):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 11,
+ \ 'text': "Replace the 'if' expression on line 11 with a 'case' expression or function clauses.",
+ \ 'type': 'W',
+ \ },
+ \ {
+ \ 'lnum': 20,
+ \ 'text': 'Remove the debug call to io:format/1 on line 20.',
+ \ 'type': 'W',
+ \ },
+ \ ],
+ \ ale_linters#erlang#elvis#Handle(bufnr(''), [
+ \ "src/foo.erl:11:no_if_expression:Replace the 'if' expression on line 11 with a 'case' expression or function clauses.",
+ \ 'src/foo.erl:20:no_debug_call:Remove the debug call to io:format/1 on line 20.',
+ \ ])
+
+Execute(Line length message shouldn't contain the line itself):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 24,
+ \ 'text': 'Line 24 is too long.',
+ \ 'type': 'W',
+ \ },
+ \ ],
+ \ ale_linters#erlang#elvis#Handle(bufnr(''), [
+ \ 'src/foo.erl:24:line_length:Line 24 is too long: io:format("Look ma, too long!"),.',
+ \ ])