Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…o raise. Closes #8
  • Loading branch information...
commit 0e38780eb44466ae35f33d28ec75536a4f3a969b 1 parent a81adbf
Michael Edgar authored
View
5 lib/laser/warnings/rescue_exception.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)
View
4 spec/warning_specs/rescue_exception_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.