Class: Roodi::Checks::AssignmentInConditionalCheck

Inherits:
Check
  • Object
show all
Defined in:
lib/roodi/checks/assignment_in_conditional_check.rb

Overview

Checks a conditional to see if it contains an assignment.

A conditional containing an assignment is likely to be a mistyped equality check. You should either fix the typo or factor out the assignment so that the code is clearer.

Constant Summary

Constants inherited from Check

Check::NODE_TYPES

Instance Method Summary collapse

Methods inherited from Check

#add_error, #end_file, #errors, #evaluate_end, #evaluate_node, #evaluate_node_end, #evaluate_node_start, #initialize, make, #position, #start_file

Constructor Details

This class inherits a constructor from Roodi::Checks::Check

Instance Method Details

#evaluate_start(node) ⇒ Object



15
16
17
# File 'lib/roodi/checks/assignment_in_conditional_check.rb', line 15

def evaluate_start(node)
  add_error("Found = in conditional.  It should probably be an ==") if has_assignment?(node[1])
end

#interesting_nodesObject



11
12
13
# File 'lib/roodi/checks/assignment_in_conditional_check.rb', line 11

def interesting_nodes
  [:if, :while]
end