Sha256: 1456d8d6676d2603839cfb4cfe0f626024983d6911961690a27cbfb67146d0bf
Contents?: true
Size: 946 Bytes
Versions: 9
Compression:
Stored size: 946 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 initialize(options = {}) super() end def interesting_nodes [:if, :while] end def evaluate(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 node.children.each { |child| found_assignment = found_assignment || has_assignment?(child) } found_assignment end end end end
Version data entries
9 entries across 9 versions & 2 rubygems