Fix Credo message types (#1963)

* Add more Credo message types
* Add tests
This commit is contained in:
Filip Vavera 2018-10-11 11:00:10 +02:00 committed by w0rp
parent bf1ac8e822
commit 3dd2d9dedd
2 changed files with 36 additions and 4 deletions

View file

@ -11,10 +11,18 @@ function! ale_linters#elixir#credo#Handle(buffer, lines) abort
let l:type = l:match[3] let l:type = l:match[3]
let l:text = l:match[4] let l:text = l:match[4]
if l:type is# 'C' " Refactoring opportunities
let l:type = 'E' if l:type is# 'F'
elseif l:type is# 'R'
let l:type = 'W' let l:type = 'W'
" Consistency
elseif l:type is# 'C'
let l:type = 'W'
" Software Design
elseif l:type is# 'D'
let l:type = 'I'
" Code Readability
elseif l:type is# 'R'
let l:type = 'I'
endif endif
call add(l:output, { call add(l:output, {

View file

@ -10,20 +10,44 @@ Execute(The credo handler should parse lines correctly):
\ { \ {
\ 'bufnr': 347, \ 'bufnr': 347,
\ 'lnum': 1, \ 'lnum': 1,
\ 'col': 24,
\ 'text': 'This code can be refactored',
\ 'type': 'W',
\ },
\ {
\ 'bufnr': 347,
\ 'lnum': 1,
\ 'col': 4, \ 'col': 4,
\ 'text': 'There is no whitespace around parentheses/brackets most of the time, but here there is.', \ 'text': 'There is no whitespace around parentheses/brackets most of the time, but here there is.',
\ 'type': 'E', \ 'type': 'W',
\ },
\ {
\ 'bufnr': 347,
\ 'lnum': 5,
\ 'col': 21,
\ 'text': 'TODO comment',
\ 'type': 'I',
\ }, \ },
\ { \ {
\ 'bufnr': 347, \ 'bufnr': 347,
\ 'lnum': 26, \ 'lnum': 26,
\ 'col': 0, \ 'col': 0,
\ 'text': 'If/else blocks should not have a negated condition in `if`.', \ 'text': 'If/else blocks should not have a negated condition in `if`.',
\ 'type': 'I',
\ },
\ {
\ 'bufnr': 347,
\ 'lnum': 15,
\ 'col': 1,
\ 'text': 'Warning in the code',
\ 'type': 'W', \ 'type': 'W',
\ }, \ },
\ ], \ ],
\ ale_linters#elixir#credo#Handle(347, [ \ ale_linters#elixir#credo#Handle(347, [
\ 'This line should be ignored completely', \ 'This line should be ignored completely',
\ 'lib/my_code/test.ex:1:24: F: This code can be refactored',
\ 'lib/filename.ex:1:4: C: There is no whitespace around parentheses/brackets most of the time, but here there is.', \ 'lib/filename.ex:1:4: C: There is no whitespace around parentheses/brackets most of the time, but here there is.',
\ 'lib/my_code/test.ex:5:21: D: TODO comment',
\ 'lib/phoenix/channel.ex:26: R: If/else blocks should not have a negated condition in `if`.', \ 'lib/phoenix/channel.ex:26: R: If/else blocks should not have a negated condition in `if`.',
\ 'lib/my_code/test.ex:15:1: W: Warning in the code',
\ ]) \ ])