class RuboCop::Cop::Lint::UnusedMethodArgument
This cop checks for unused method arguments.
@example
# bad def some_method(used, unused, _unused_but_allowed) puts used end
@example
# good def some_method(used, _unused, _unused_but_allowed) puts used end
Public Instance Methods
check_argument(variable)
click to toggle source
Calls superclass method
RuboCop::Cop::Lint::UnusedArgument#check_argument
# File lib/rubocop/cop/lint/unused_method_argument.rb, line 26 def check_argument(variable) return unless variable.method_argument? return if variable.keyword_argument? && cop_config['AllowUnusedKeywordArguments'] if cop_config['IgnoreEmptyMethods'] body = variable.scope.node.body return if body.nil? end super end
message(variable)
click to toggle source
# File lib/rubocop/cop/lint/unused_method_argument.rb, line 40 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