Sha256: dd470ad8d84f41535f18c2a5e791557fa5712ea3f29a3c3431d9fa982d7e9e1b
Contents?: true
Size: 961 Bytes
Versions: 15
Compression:
Stored size: 961 Bytes
Contents
require 'roodi/checks/check' module Roodi module Checks # 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. class AssignmentInConditionalCheck < Check def interesting_nodes [:if, :while] end def evaluate_start(node) add_error("Found = in conditional. It should probably be an ==") if has_assignment?(node[1]) end private def has_assignment?(node) found_assignment = false found_assignment = found_assignment || node.node_type == :lasgn 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 end end
Version data entries
15 entries across 15 versions & 2 rubygems