Sha256: 821468ba628d6fd988ade1a532f2412536b7f48695c990bf20d86ed9328a13c6

Contents?: true

Size: 1.43 KB

Versions: 11

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop checks for unused method arguments.
      #
      # @example
      #
      #   def some_method(used, unused, _unused_but_allowed)
      #     puts used
      #   end
      class UnusedMethodArgument < Cop
        include UnusedArgument

        def check_argument(variable)
          return unless variable.method_argument?
          return if variable.keyword_argument? &&
                    cop_config['AllowUnusedKeywordArguments']

          if cop_config['IgnoreEmptyMethods']
            _name, _args, body = *variable.scope.node
            return if body.nil?
          end

          super
        end

        def message(variable)
          message = String.new("Unused method argument - `#{variable.name}`.")

          unless variable.keyword_argument?
            message << " If it's necessary, use `_` or `_#{variable.name}` " \
                       "as an argument name to indicate that it won't be used."
          end

          scope = variable.scope
          all_arguments = scope.variables.each_value.select(&:method_argument?)

          if all_arguments.none?(&:referenced?)
            message << " You can also write as `#{scope.name}(*)` " \
                       'if you want the method to accept any arguments ' \
                       "but don't care about them."
          end

          message
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/lint/unused_method_argument.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/lint/unused_method_argument.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/lint/unused_method_argument.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/lint/unused_method_argument.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/lint/unused_method_argument.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/lint/unused_method_argument.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.46.0 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.45.0 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.44.1 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.44.0 lib/rubocop/cop/lint/unused_method_argument.rb