Sha256: e531b08a01a50601ddd98ffc4781f5f0dfaa40c51cf08f40c2ea5e17169d4986

Contents?: true

Size: 1.83 KB

Versions: 52

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

module RuboCop
  module AST
    # Common functionality for nodes that are parameterized:
    # `send`, `super`, `zsuper`, `def`, `defs`
    module ParameterizedNode
      # Checks whether this node's arguments are wrapped in parentheses.
      #
      # @return [Boolean] whether this node's arguments are
      #                   wrapped in parentheses
      def parenthesized?
        loc.end&.is?(')')
      end

      # A shorthand for getting the first argument of the node.
      # Equivalent to `arguments.first`.
      #
      # @return [Node, nil] the first argument of the node,
      #                     or `nil` if there are no arguments
      def first_argument
        arguments[0]
      end

      # A shorthand for getting the last argument of the node.
      # Equivalent to `arguments.last`.
      #
      # @return [Node, nil] the last argument of the node,
      #                     or `nil` if there are no arguments
      def last_argument
        arguments[-1]
      end

      # Checks whether this node has any arguments.
      #
      # @return [Boolean] whether this node has any arguments
      def arguments?
        !arguments.empty?
      end

      # Checks whether any argument of the node is a splat
      # argument, i.e. `*splat`.
      #
      # @return [Boolean] whether the node is a splat argument
      def splat_argument?
        arguments? &&
          (arguments.any?(&:splat_type?) || arguments.any?(&:restarg_type?))
      end
      alias rest_argument? splat_argument?

      # Whether the last argument of the node is a block pass,
      # i.e. `&block`.
      #
      # @return [Boolean] whether the last argument of the node is a block pass
      def block_argument?
        arguments? &&
          (last_argument.block_pass_type? || last_argument.blockarg_type?)
      end
    end
  end
end

Version data entries

52 entries across 33 versions & 5 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/ast/node/mixin/parameterized_node.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/node/mixin/parameterized_node.rb
rubocop-ast-0.0.3 lib/rubocop/ast/node/mixin/parameterized_node.rb
rubocop-ast-0.0.2 lib/rubocop/ast/node/mixin/parameterized_node.rb
rubocop-ast-0.0.1 lib/rubocop/ast/node/mixin/parameterized_node.rb
rubocop-0.83.0 lib/rubocop/ast/node/mixin/parameterized_node.rb
rubocop-0.82.0 lib/rubocop/ast/node/mixin/parameterized_node.rb
rubocop-0.81.0 lib/rubocop/ast/node/mixin/parameterized_node.rb
rubocop-0.80.1 lib/rubocop/ast/node/mixin/parameterized_node.rb
rubocop-0.80.0 lib/rubocop/ast/node/mixin/parameterized_node.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/ast/node/mixin/parameterized_node.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/ast/node/mixin/parameterized_node.rb
rubocop-0.79.0 lib/rubocop/ast/node/mixin/parameterized_node.rb
rubocop-0.78.0 lib/rubocop/ast/node/mixin/parameterized_node.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/ast/node/mixin/parameterized_node.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/ast/node/mixin/parameterized_node.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/ast/node/mixin/parameterized_node.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/ast/node/mixin/parameterized_node.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/ast/node/mixin/parameterized_node.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/ast/node/mixin/parameterized_node.rb