Sha256: 40d600b9dbf4b60a271ea25fff3db1c93b3a8c9524e10288b710e2733d8623f0

Contents?: true

Size: 1.15 KB

Versions: 20

Compression:

Stored size: 1.15 KB

Contents

# encoding: utf-8

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?
          super
        end

        def message(variable)
          message = "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

20 entries across 20 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/lint/unused_method_argument.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.34.2 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.34.1 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.34.0 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.33.0 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.32.1 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.32.0 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.31.0 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.30.1 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.30.0 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.29.1 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.29.0 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.28.0 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.27.1 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.27.0 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.26.1 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.26.0 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.25.0 lib/rubocop/cop/lint/unused_method_argument.rb
rubocop-0.24.1 lib/rubocop/cop/lint/unused_method_argument.rb