Fix #1412 - Use --stdin-filename for newer reek versions

This commit is contained in:
w0rp 2018-07-01 10:21:59 +01:00
parent ee81351a63
commit b88bf6ecba
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
2 changed files with 76 additions and 16 deletions

View File

@ -4,21 +4,27 @@
call ale#Set('ruby_reek_show_context', 0)
call ale#Set('ruby_reek_show_wiki_link', 0)
function! ale_linters#ruby#reek#Handle(buffer, lines) abort
let l:output = []
function! ale_linters#ruby#reek#VersionCheck(buffer) abort
" If we have previously stored the version number in a cache, then
" don't look it up again.
if ale#semver#HasVersion('reek')
" Returning an empty string skips this command.
return ''
endif
for l:error in ale#util#FuzzyJSONDecode(a:lines, [])
for l:location in l:error.lines
call add(l:output, {
\ 'lnum': l:location,
\ 'type': 'W',
\ 'text': s:BuildText(a:buffer, l:error),
\ 'code': l:error.smell_type,
\})
endfor
endfor
return 'reek --version'
endfunction
return l:output
function! ale_linters#ruby#reek#GetCommand(buffer, version_output) abort
let l:version = ale#semver#GetVersion('reek', a:version_output)
" Tell reek what the filename is if the version of reek is new enough.
let l:display_name_args = ale#semver#GTE(l:version, [5, 0, 0])
\ ? ' --stdin-filename %s'
\ : ''
return 'reek -f json --no-progress --no-color'
\ . l:display_name_args
endfunction
function! s:BuildText(buffer, error) abort
@ -37,9 +43,29 @@ function! s:BuildText(buffer, error) abort
return join(l:parts, ' ')
endfunction
function! ale_linters#ruby#reek#Handle(buffer, lines) abort
let l:output = []
for l:error in ale#util#FuzzyJSONDecode(a:lines, [])
for l:location in l:error.lines
call add(l:output, {
\ 'lnum': l:location,
\ 'type': 'W',
\ 'text': s:BuildText(a:buffer, l:error),
\ 'code': l:error.smell_type,
\})
endfor
endfor
return l:output
endfunction
call ale#linter#Define('ruby', {
\ 'name': 'reek',
\ 'executable': 'reek',
\ 'command': 'reek -f json --no-progress --no-color',
\ 'name': 'reek',
\ 'executable': 'reek',
\ 'command_chain': [
\ {'callback': 'ale_linters#ruby#reek#VersionCheck'},
\ {'callback': 'ale_linters#ruby#reek#GetCommand'},
\ ],
\ 'callback': 'ale_linters#ruby#reek#Handle',
\})

View File

@ -0,0 +1,34 @@
Before:
runtime ale_linters/ruby/reek.vim
call ale#test#SetDirectory('/testplugin/test/command_callback')
After:
call ale#test#RestoreDirectory()
call ale#linter#Reset()
call ale#semver#ResetVersionCache()
Execute(The reek callbacks should return the correct default values):
AssertEqual
\ 'reek --version',
\ ale_linters#ruby#reek#VersionCheck(bufnr(''))
AssertEqual
\ 'reek -f json --no-progress --no-color --stdin-filename %s',
\ ale_linters#ruby#reek#GetCommand(bufnr(''), ['reek 5.0.0'])
" Try with older versions.
call ale#semver#ResetVersionCache()
AssertEqual
\ 'reek -f json --no-progress --no-color',
\ ale_linters#ruby#reek#GetCommand(bufnr(''), ['reek 4.8.2'])
Execute(The reek version check should be cached):
AssertEqual
\ 'reek -f json --no-progress --no-color --stdin-filename %s',
\ ale_linters#ruby#reek#GetCommand(bufnr(''), ['reek 5.0.0'])
AssertEqual
\ '',
\ ale_linters#ruby#reek#VersionCheck(bufnr(''))
AssertEqual
\ 'reek -f json --no-progress --no-color --stdin-filename %s',
\ ale_linters#ruby#reek#GetCommand(bufnr(''), [])