Sha256: a7be09734106770c7bb849230e3aa20583a6973304fcd26afa57677aaf237aa0

Contents?: true

Size: 855 Bytes

Versions: 16

Compression:

Stored size: 855 Bytes

Contents

# 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)
        return unless node.setter_method?

        rhs = extract_rhs(node)

        return unless rhs

        check_assignment(node, rhs)
      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.last_argument
        end

        rhs
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.57.2 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.57.1 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.57.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.56.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.55.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.54.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.53.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.52.1 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.52.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.51.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.50.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.49.1 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.49.0 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.48.1 lib/rubocop/cop/mixin/check_assignment.rb
rubocop-0.48.0 lib/rubocop/cop/mixin/check_assignment.rb