Sha256: 546fe5566d707880a2b62160b7a99aab123335ed3c5d81026c7c439c7376d1ab

Contents?: true

Size: 1.01 KB

Versions: 13

Compression:

Stored size: 1.01 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

module RuboCop
  module Cop
    # Common functionality for checking assignment nodes.
    module CheckAssignment
      Util::ASGN_NODES.each do |type|
        define_method("on_#{type}") do |node|
          check_assignment(node, extract_rhs(node))
        end
      end

      def on_send(node)
        # we only want to indent relative to the receiver
        # when the method called looks like a setter
        return unless node.asgn_method_call?

        # This will match if, case, begin, blocks, etc.
        rhs = extract_rhs(node)
        check_assignment(node, rhs) if rhs.is_a?(AST::Node)
      end

      module_function

      def extract_rhs(node)
        if node.casgn_type?
          _scope, _lhs, rhs = *node
        elsif node.op_asgn_type?
          _lhs, _op, rhs = *node
        elsif Util::ASGN_NODES.include?(node.type)
          _lhs, rhs = *node
        elsif node.send_type?
          rhs = node.children.last
        end

        rhs
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/check_assignment.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.43.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.42.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.41.2 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.41.1 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.41.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.40.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.39.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.38.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.37.2 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.37.1 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.37.0 lib/rubocop/cop/mixin/check_assignment.rb