Sha256: be020932eef065f1817413ec5c869b0a8bf4247c21a57bda2ea03e11cef9068b

Contents?: true

Size: 1.18 KB

Versions: 16

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module InternalAffairs
      # Checks that node destructuring is done either using the node
      # extensions or using a splat.
      #
      # @example Using splat expansion
      #
      #   # bad
      #   receiver, method_name, arguments = send_node.children
      #
      #   # good
      #   receiver, method_name, arguments = *send_node
      #
      # @example Using node extensions
      #
      #   # bad
      #   _receiver, method_name, _arguments = send_node.children
      #
      #   # good
      #   method_name = send_node.method_name
      class NodeDestructuring < Cop
        MSG = 'Use the methods provided with the node extensions, or ' \
              'destructure the node using `*`.'.freeze

        def_node_matcher :node_children_destructuring?, <<-PATTERN
          (masgn (mlhs ...) (send (send nil? [#node_suffix? _]) :children))
        PATTERN

        def on_masgn(node)
          node_children_destructuring?(node) do
            add_offense(node)
          end
        end

        private

        def node_suffix?(method_name)
          method_name.to_s.end_with?('node')
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
rubocop-0.59.2 lib/rubocop/cop/internal_affairs/node_destructuring.rb
rubocop-0.59.1 lib/rubocop/cop/internal_affairs/node_destructuring.rb
rubocop-0.59.0 lib/rubocop/cop/internal_affairs/node_destructuring.rb
rubocop-0.58.2 lib/rubocop/cop/internal_affairs/node_destructuring.rb
rubocop-0.58.1 lib/rubocop/cop/internal_affairs/node_destructuring.rb
rubocop-0.58.0 lib/rubocop/cop/internal_affairs/node_destructuring.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/internal_affairs/node_destructuring.rb
rubocop-0.57.2 lib/rubocop/cop/internal_affairs/node_destructuring.rb
rubocop-0.57.1 lib/rubocop/cop/internal_affairs/node_destructuring.rb
rubocop-0.57.0 lib/rubocop/cop/internal_affairs/node_destructuring.rb
rubocop-0.56.0 lib/rubocop/cop/internal_affairs/node_destructuring.rb
rubocop-0.55.0 lib/rubocop/cop/internal_affairs/node_destructuring.rb
rubocop-0.54.0 lib/rubocop/cop/internal_affairs/node_destructuring.rb
rubocop-0.53.0 lib/rubocop/cop/internal_affairs/node_destructuring.rb
rubocop-0.52.1 lib/rubocop/cop/internal_affairs/node_destructuring.rb
rubocop-0.52.0 lib/rubocop/cop/internal_affairs/node_destructuring.rb