Browse files

clean up empty rescue body check to be more efficient.

  • Loading branch information...
1 parent 67e9d9f commit 50ee7a6b6e7a181f56e565241b15b63d21c6bb82 @martinjandrews martinjandrews committed Aug 9, 2009
Showing with 5 additions and 8 deletions.
  1. +5 −8 lib/roodi/checks/empty_rescue_body_check.rb
View
13 lib/roodi/checks/empty_rescue_body_check.rb
@@ -7,28 +7,25 @@ module Checks
# When the body of a rescue block is empty, exceptions can get caught and swallowed without
# any feedback to the user.
class EmptyRescueBodyCheck < Check
- STATEMENT_NODES = [:fcall, :return, :attrasgn, :vcall, :nil, :call]
+ STATEMENT_NODES = [:fcall, :return, :attrasgn, :vcall, :nil, :call, :lasgn]
def interesting_nodes
[:resbody]
end
def evaluate_start(node)
- add_error("Rescue block should not be empty.") unless has_statement?(node)
+ add_error("Rescue block should not be empty.") unless has_statement?(node.children[1])
end
private
def has_statement?(node)
- has_local_statement?(node) or node.children.any? { |child| has_statement?(child) }
+ false unless node
+ has_local_statement?(node) or node.children.any? { |child| has_statement?(child) } if node
end
def has_local_statement?(node)
- STATEMENT_NODES.include?(node.node_type) or assigning_other_than_exception_to_local_variable?(node)
- end
-
- def assigning_other_than_exception_to_local_variable?(node)
- node.node_type == :lasgn && node[2].to_a != [:gvar, :$!]
+ STATEMENT_NODES.include?(node.node_type)
end
end
end

0 comments on commit 50ee7a6

Please sign in to comment.