Sha256: e686f6afbaa4321d133cc6474728c5c1a23ae1992cccc993492964db61df3f84

Contents?: true

Size: 752 Bytes

Versions: 2

Compression:

Stored size: 752 Bytes

Contents

require 'simplabs/excellent/checks/base'

module Simplabs

  module Excellent

    module Checks

      class AssignmentInConditionalCheck < Base

        def initialize(options = {})
          super()
        end

        def interesting_nodes
          [:if, :while, :until]
        end

        def evaluate(node)
          add_error('Assignment in condition.') 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

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simplabs-excellent-1.0.0 lib/simplabs/excellent/checks/assignment_in_conditional_check.rb
simplabs-excellent-1.0.1 lib/simplabs/excellent/checks/assignment_in_conditional_check.rb