summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2019-10-07 19:17:55 +0100
committerGitHub <noreply@github.com>2019-10-07 19:17:55 +0100
commit32b784219b91a99fb05a78825ce64c5a4f98f253 (patch)
treea597bd6a3a3d00671c25d976f93dc348b6df6f2e
parenta486aa1d24294c5b14c8b2763a3b5ffdc39d0739 (diff)
parent8aa1578605f88e237f2fc0307f176bd7171eb23e (diff)
downloadale-32b784219b91a99fb05a78825ce64c5a4f98f253.zip
Merge pull request #2694 from elebow/add-ruby-debride
Add ruby debride (closes #2471)
-rw-r--r--ale_linters/ruby/debride.vim42
-rw-r--r--doc/ale-ruby.txt26
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/handler/test_debride_handler.vader27
6 files changed, 95 insertions, 3 deletions
diff --git a/ale_linters/ruby/debride.vim b/ale_linters/ruby/debride.vim
new file mode 100644
index 00000000..0a45644e
--- /dev/null
+++ b/ale_linters/ruby/debride.vim
@@ -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',
+\})
diff --git a/doc/ale-ruby.txt b/doc/ale-ruby.txt
index e373ab8e..a27a20b2 100644
--- a/doc/ale-ruby.txt
+++ b/doc/ale-ruby.txt
@@ -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 changed to modify flags given to debride.
+
+
===============================================================================
rails_best_practices *ale-ruby-rails_best_practices*
@@ -91,7 +111,7 @@ g:ale_ruby_rubocop_options *g:ale_ruby_rubocop_options*
Type: |String|
Default: `''`
- This variable can be change to modify flags given to rubocop.
+ This variable can be changed to modify flags given to rubocop.
===============================================================================
@@ -146,7 +166,7 @@ g:ale_ruby_sorbet_options *g:ale_ruby_sorbet_options*
Type: |String|
Default: `''`
- This variable can be change to modify flags given to sorbet.
+ This variable can be changed to modify flags given to sorbet.
===============================================================================
@@ -166,7 +186,7 @@ g:ale_ruby_standardrb_options *g:ale_ruby_standardrb_options*
Type: |String|
Default: `''`
- This variable can be change to modify flags given to standardrb.
+ This variable can be changed to modify flags given to standardrb.
===============================================================================
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index a29ea6a3..7a536239 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -391,6 +391,7 @@ Notes:
* `rpmlint`
* Ruby
* `brakeman`
+ * `debride`
* `rails_best_practices`!!
* `reek`
* `rubocop`
diff --git a/doc/ale.txt b/doc/ale.txt
index b368afd3..42dba257 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2395,6 +2395,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|
diff --git a/supported-tools.md b/supported-tools.md
index 1a297946..ad72c267 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -400,6 +400,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)
diff --git a/test/handler/test_debride_handler.vader b/test/handler/test_debride_handler.vader
new file mode 100644
index 00000000..62851468
--- /dev/null
+++ b/test/handler/test_debride_handler.vader
@@ -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'
+ \])