forked from dense-analysis/ale
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Elvis][1] is an Erlang style reviewer. [1]: https://github.com/inaka/elvis
- Loading branch information
1 parent
5daa59b
commit cf91a6b
Showing
7 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
\}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,7 @@ Notes: | |
* `erubis` | ||
* `ruumba` | ||
* Erlang | ||
* `elvis`!! | ||
* `erlc` | ||
* `SyntaxErl` | ||
* Fish | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
test/command_callback/test_erlang_elvis_command_callback.vader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!"),.', | ||
\ ]) |