Sha256: aa40378c7b7b1be0902cb2b20d94fd66336dfeaab2f18724e21898f0589a63d8

Contents?: true

Size: 735 Bytes

Versions: 4

Compression:

Stored size: 735 Bytes

Contents

require 'simplabs/excellent/checks/base'

module Simplabs

  module Excellent

    module Checks

      # This check reports conditionals that test an assignment as in
      #
      #  something(var) if var = method()
      #
      # Assignments in conditions are often typos.
      #
      # ==== Applies to
      #
      # * +if+
      # * +else+
      # * +while+
      # * +until+
      class AssignmentInConditionalCheck < Base

        def initialize(options = {}) #:nodoc:
          super()
          @interesting_nodes = [:if, :while, :until]
        end

        def evaluate(context) #:nodoc:
          add_warning(context, 'Assignment in condition.') if context.tests_assignment?
        end

      end

    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
simplabs-excellent-1.2.1 lib/simplabs/excellent/checks/assignment_in_conditional_check.rb
simplabs-excellent-1.2.2 lib/simplabs/excellent/checks/assignment_in_conditional_check.rb
simplabs-excellent-1.3.0 lib/simplabs/excellent/checks/assignment_in_conditional_check.rb
simplabs-excellent-1.3.1 lib/simplabs/excellent/checks/assignment_in_conditional_check.rb