debride: Add debride linter (closes #2471)
This commit is contained in:
parent
28c93ab185
commit
501af8dd8b
6 changed files with 92 additions and 0 deletions
42
ale_linters/ruby/debride.vim
Normal file
42
ale_linters/ruby/debride.vim
Normal 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',
|
||||||
|
\})
|
|
@ -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.
|
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*
|
rails_best_practices *ale-ruby-rails_best_practices*
|
||||||
|
|
|
@ -386,6 +386,7 @@ Notes:
|
||||||
* `rpmlint`
|
* `rpmlint`
|
||||||
* Ruby
|
* Ruby
|
||||||
* `brakeman`
|
* `brakeman`
|
||||||
|
* `debride`
|
||||||
* `rails_best_practices`!!
|
* `rails_best_practices`!!
|
||||||
* `reek`
|
* `reek`
|
||||||
* `rubocop`
|
* `rubocop`
|
||||||
|
|
|
@ -2268,6 +2268,7 @@ documented in additional help files.
|
||||||
write-good............................|ale-restructuredtext-write-good|
|
write-good............................|ale-restructuredtext-write-good|
|
||||||
ruby....................................|ale-ruby-options|
|
ruby....................................|ale-ruby-options|
|
||||||
brakeman..............................|ale-ruby-brakeman|
|
brakeman..............................|ale-ruby-brakeman|
|
||||||
|
debride...............................|ale-ruby-debride|
|
||||||
rails_best_practices..................|ale-ruby-rails_best_practices|
|
rails_best_practices..................|ale-ruby-rails_best_practices|
|
||||||
reek..................................|ale-ruby-reek|
|
reek..................................|ale-ruby-reek|
|
||||||
rubocop...............................|ale-ruby-rubocop|
|
rubocop...............................|ale-ruby-rubocop|
|
||||||
|
|
|
@ -395,6 +395,7 @@ formatting.
|
||||||
* [rpmlint](https://github.com/rpm-software-management/rpmlint) :warning: (see `:help ale-integration-spec`)
|
* [rpmlint](https://github.com/rpm-software-management/rpmlint) :warning: (see `:help ale-integration-spec`)
|
||||||
* Ruby
|
* Ruby
|
||||||
* [brakeman](http://brakemanscanner.org/) :floppy_disk:
|
* [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:
|
* [rails_best_practices](https://github.com/flyerhzm/rails_best_practices) :floppy_disk:
|
||||||
* [reek](https://github.com/troessner/reek)
|
* [reek](https://github.com/troessner/reek)
|
||||||
* [rubocop](https://github.com/bbatsov/rubocop)
|
* [rubocop](https://github.com/bbatsov/rubocop)
|
||||||
|
|
27
test/handler/test_debride_handler.vader
Normal file
27
test/handler/test_debride_handler.vader
Normal 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'
|
||||||
|
\])
|
Reference in a new issue