Sha256: c112d6d2cfae12ccf1a9b47eab68aa7d4b15da7a46d062da070b3b1d0a525ba0

Contents?: true

Size: 1.18 KB

Versions: 6817

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

6,817 entries across 6,811 versions & 25 rubygems

Version Path
ory-kratos-client-0.8.2.alpha1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
ory-client-0.0.1.alpha31 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
primary_connect_proto-0.4.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
primary_connect_proto-0.3.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
primary_connect_proto-0.2.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
primary_connect_proto-0.1.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
ory-client-0.0.1.alpha30 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
ory-client-0.0.1.alpha29 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
primary_connect_proto-0.0.6 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
ory-client-0.0.1.alpha28 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
primary_connect_proto-0.0.5 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
ory-client-0.0.1.alpha27 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
ory-client-0.0.1.alpha24 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
primary_connect_proto-0.0.4 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
primary_connect_proto-0.0.3 vendor/bundle/ruby/2.6.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
ory-client-0.0.1.alpha23 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
ory-kratos-client-0.8.0.alpha2 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
ory-client-0.0.1.alpha21 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
ory-keto-client-0.7.0.alpha1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb
ory-keto-client-0.7.0.alpha0 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/internal_affairs/node_destructuring.rb