debride: Add debride linter (closes #2471)

This commit is contained in:
Eddie Lebow 2019-08-13 01:32:18 -04:00
parent 28c93ab185
commit 501af8dd8b
No known key found for this signature in database
GPG Key ID: 21A09CFD989FD546
6 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,42 @@
" Author: Eddie Lebow https://github.com/elebow
" Description: debride, a dead method detector for Ruby files
call ale#Set('ruby_debride_executable', 'debride')
call ale#Set('ruby_debride_options', '')
function! ale_linters#ruby#debride#GetCommand(buffer) abort
let l:executable = ale#Var(a:buffer, 'ruby_debride_executable')
return ale#handlers#ruby#EscapeExecutable(l:executable, 'debride')
\ . ale#Var(a:buffer, 'ruby_debride_options')
\ . ' %s'
endfunction
function! ale_linters#ruby#debride#HandleOutput(buffer, lines) abort
let l:output = []
for l:line in a:lines
if l:line !~# '^ '
continue
endif
let l:elements = split(l:line)
let l:method_name = l:elements[0]
let l:lnum = split(l:elements[1], ':')[1]
call add(l:output, {
\ 'lnum': 0 + l:lnum,
\ 'text': 'Possible unused method: ' . l:method_name,
\ 'type': 'W',
\})
endfor
return l:output
endfunction
call ale#linter#Define('ruby', {
\ 'name': 'debride',
\ 'executable': {b -> ale#Var(b, 'ruby_debride_executable')},
\ 'command': function('ale_linters#ruby#debride#GetCommand'),
\ 'callback': 'ale_linters#ruby#debride#HandleOutput',
\})

View File

@ -21,6 +21,26 @@ g:ale_ruby_brakeman_options *g:ale_ruby_brakeman_options*
The contents of this variable will be passed through to brakeman.
===============================================================================
debride *ale-ruby-debride*
g:ale_ruby_debride_executable *g:ale_ruby_debride_executable*
*b:ale_ruby_debride_executable*
Type: String
Default: `'debride'`
Override the invoked debride binary. Set this to `'bundle'` to invoke
`'bundle` `exec` debride'.
g:ale_ruby_debride_options *g:ale_ruby_debride_options*
*b:ale_ruby_debride_options*
Type: |String|
Default: `''`
This variable can be change to modify flags given to debride.
===============================================================================
rails_best_practices *ale-ruby-rails_best_practices*

View File

@ -386,6 +386,7 @@ Notes:
* `rpmlint`
* Ruby
* `brakeman`
* `debride`
* `rails_best_practices`!!
* `reek`
* `rubocop`

View File

@ -2268,6 +2268,7 @@ documented in additional help files.
write-good............................|ale-restructuredtext-write-good|
ruby....................................|ale-ruby-options|
brakeman..............................|ale-ruby-brakeman|
debride...............................|ale-ruby-debride|
rails_best_practices..................|ale-ruby-rails_best_practices|
reek..................................|ale-ruby-reek|
rubocop...............................|ale-ruby-rubocop|

View File

@ -395,6 +395,7 @@ formatting.
* [rpmlint](https://github.com/rpm-software-management/rpmlint) :warning: (see `:help ale-integration-spec`)
* Ruby
* [brakeman](http://brakemanscanner.org/) :floppy_disk:
* [debride](https://github.com/seattlerb/debride) :floppy_disk:
* [rails_best_practices](https://github.com/flyerhzm/rails_best_practices) :floppy_disk:
* [reek](https://github.com/troessner/reek)
* [rubocop](https://github.com/bbatsov/rubocop)

View File

@ -0,0 +1,27 @@
Before:
runtime ale_linters/ruby/debride.vim
After:
call ale#linter#Reset()
Execute(The debride linter parses output correctly):
AssertEqual
\ [
\ {
\ 'lnum': 2,
\ 'text': 'Possible unused method: image_tags',
\ 'type': 'W',
\ },
\ {
\ 'lnum': 7,
\ 'text': 'Possible unused method: not_deleted',
\ 'type': 'W',
\ }
\ ],
\ ale_linters#ruby#debride#HandleOutput(0, [
\ 'These methods MIGHT not be called:',
\ '',
\ 'Image',
\ ' image_tags app/models/image.rb:2',
\ ' not_deleted app/models/image.rb:7'
\])