This cop checks for unused block arguments.
@example
do_something do |used, unused, _unused_but_allowed| puts used end
# File lib/rubocop/cop/lint/unused_block_argument.rb, line 16 def check_argument(variable) return unless variable.block_argument? super end
# File lib/rubocop/cop/lint/unused_block_argument.rb, line 21 def message(variable) message = "Unused block argument - `#{variable.name}`. " scope = variable.scope all_arguments = scope.variables.each_value.select(&:block_argument?) if lambda?(scope.node) message << message_for_lambda(variable, all_arguments) else message << message_for_normal_block(variable, all_arguments) end message end
# File lib/rubocop/cop/lint/unused_block_argument.rb, line 48 def message_for_lambda(variable, all_arguments) message = message_for_underscore_prefix(variable) if all_arguments.none?(&:referenced?) message << ' Also consider using a proc without arguments ' 'instead of a lambda if you want it ' "to accept any arguments but don't care about them." end message end
# File lib/rubocop/cop/lint/unused_block_argument.rb, line 36 def message_for_normal_block(variable, all_arguments) if all_arguments.none?(&:referenced?) if all_arguments.count > 1 "You can omit all the arguments if you don't care about them." else "You can omit the argument if you don't care about it." end else message_for_underscore_prefix(variable) end end
Generated with the Darkfish Rdoc Generator 2.