Sha256: a18fd8d9739d06255d915c462e2d1ca2ad224103411dcafddd9c13c1400b2ab9

Contents?: true

Size: 1.56 KB

Versions: 75

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop checks for circular argument references in optional keyword
      # arguments and optional ordinal arguments.
      #
      # This cop mirrors a warning produced by MRI since 2.2.
      #
      # @example
      #
      #   # bad
      #
      #   def bake(pie: pie)
      #     pie.heat_up
      #   end
      #
      # @example
      #
      #   # good
      #
      #   def bake(pie:)
      #     pie.refrigerate
      #   end
      #
      # @example
      #
      #   # good
      #
      #   def bake(pie: self.pie)
      #     pie.feed_to(user)
      #   end
      #
      # @example
      #
      #   # bad
      #
      #   def cook(dry_ingredients = dry_ingredients)
      #     dry_ingredients.reduce(&:+)
      #   end
      #
      # @example
      #
      #   # good
      #
      #   def cook(dry_ingredients = self.dry_ingredients)
      #     dry_ingredients.combine
      #   end
      class CircularArgumentReference < Base
        MSG = 'Circular argument reference - `%<arg_name>s`.'

        def on_kwoptarg(node)
          check_for_circular_argument_references(*node)
        end

        def on_optarg(node)
          check_for_circular_argument_references(*node)
        end

        private

        def check_for_circular_argument_references(arg_name, arg_value)
          return unless arg_value.lvar_type?
          return unless arg_value.to_a == [arg_name]

          add_offense(arg_value, message: format(MSG, arg_name: arg_name))
        end
      end
    end
  end
end

Version data entries

75 entries across 75 versions & 8 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/circular_argument_reference.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/circular_argument_reference.rb
rubocop-1.29.1 lib/rubocop/cop/lint/circular_argument_reference.rb
rubocop-1.29.0 lib/rubocop/cop/lint/circular_argument_reference.rb
rubocop-1.28.2 lib/rubocop/cop/lint/circular_argument_reference.rb
rubocop-1.28.1 lib/rubocop/cop/lint/circular_argument_reference.rb
rubocop-1.28.0 lib/rubocop/cop/lint/circular_argument_reference.rb
rubocop-1.27.0 lib/rubocop/cop/lint/circular_argument_reference.rb
rubocop-1.26.1 lib/rubocop/cop/lint/circular_argument_reference.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/circular_argument_reference.rb
rubocop-1.26.0 lib/rubocop/cop/lint/circular_argument_reference.rb
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/circular_argument_reference.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/circular_argument_reference.rb
rubocop-1.25.1 lib/rubocop/cop/lint/circular_argument_reference.rb
rubocop-1.25.0 lib/rubocop/cop/lint/circular_argument_reference.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/circular_argument_reference.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/circular_argument_reference.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/cop/lint/circular_argument_reference.rb
rubocop-1.24.1 lib/rubocop/cop/lint/circular_argument_reference.rb
rubocop-1.24.0 lib/rubocop/cop/lint/circular_argument_reference.rb