Permalink
Browse files

Empty rescue clauses no longer cause the 'rescue Exception' warning t…

…o raise. Closes #8
  • Loading branch information...
1 parent a81adbf commit 0e38780eb44466ae35f33d28ec75536a4f3a969b Michael Edgar committed Sep 11, 2011
Showing with 7 additions and 2 deletions.
  1. +3 −2 lib/laser/warnings/rescue_exception.rb
  2. +4 −0 spec/warning_specs/rescue_exception_spec.rb
@@ -9,6 +9,7 @@ class Laser::RescueExceptionWarning < Laser::FileWarning
def match?(body = self.body)
find_sexps(:rescue).map do |_, types, name|
+ next if types.nil?
case types[0]
when :mrhs_new_from_args
list = types[1] + types[2..-1]
@@ -23,8 +24,8 @@ def match?(body = self.body)
warning.line_number = type[1][2][1]
warning
end
- end.compact
- end.flatten
+ end
+ end.flatten.compact
end
def fix(body = self.body)
@@ -37,6 +37,10 @@
RescueExceptionWarning.should_not warn('begin; puts x; rescue StandardError, StandardError => err; end')
end
+ it 'does not match when a rescue has no types listed' do
+ RescueExceptionWarning.should_not warn('begin; puts x; rescue; end')
+ end
+
describe '#fix' do
it 'fixes a rescue of Exception as the only type' do
input = <<-EOF

0 comments on commit 0e38780

Please sign in to comment.