Skip to content
Browse files

be more specific about when to search children.

inadvertently fixes a big where assignments inside blocks were accidentally reported. :)
  • Loading branch information...
1 parent e84a7ea commit 078b7d9b7a6905a35d09bea7e24c334df181369d @martinjandrews martinjandrews committed Aug 9, 2009
View
4 lib/roodi/checks/assignment_in_conditional_check.rb
@@ -24,7 +24,9 @@ def evaluate_start(node)
def has_assignment?(node)
found_assignment = false
found_assignment = found_assignment || node.node_type == :lasgn
- node.children.each { |child| found_assignment = found_assignment || has_assignment?(child) }
+ if (node.node_type == :and or node.node_type == :or)
+ node.children.each { |child| found_assignment = found_assignment || has_assignment?(child) }
+ end
found_assignment
end
end
View
38 spec/roodi/checks/assignment_in_conditional_check_spec.rb
@@ -62,28 +62,40 @@
errors[0].to_s.should eql("dummy-file.rb:1 - Found = in conditional. It should probably be an ==")
end
- it "should reject a real example 1" do
+ it "should reject an assignment after an 'and'" do
content = <<-END
- if match = matches_dynamic_method?(method_symbol)
- case match[1]
- when 'create' then new(match[2], *parameters).mail
- when 'deliver' then new(match[2], *parameters).deliver!
- when 'new' then nil
- else super
- end
- else
- super
- end
+ call_foo if bar and bam = baz
END
@roodi.check_content(content)
errors = @roodi.errors
errors.should_not be_empty
errors[0].to_s.should eql("dummy-file.rb:1 - Found = in conditional. It should probably be an ==")
end
- it "should reject a real example 2" do
+
+ it "should reject an assignment after an 'or'" do
content = <<-END
- call_foo if bar and bam = baz
+ call_foo if bar or bam = baz
+ END
+ @roodi.check_content(content)
+ errors = @roodi.errors
+ errors.should_not be_empty
+ errors[0].to_s.should eql("dummy-file.rb:1 - Found = in conditional. It should probably be an ==")
+ end
+
+ it "should reject an assignment after an '&&'" do
+ content = <<-END
+ call_foo if bar && bam = baz
+ END
+ @roodi.check_content(content)
+ errors = @roodi.errors
+ errors.should_not be_empty
+ errors[0].to_s.should eql("dummy-file.rb:1 - Found = in conditional. It should probably be an ==")
+ end
+
+ it "should reject an assignment after an '||'" do
+ content = <<-END
+ call_foo if bar || bam = baz
END
@roodi.check_content(content)
errors = @roodi.errors

0 comments on commit 078b7d9

Please sign in to comment.
Something went wrong with that request. Please try again.