class RuboCop::Cop::Lint::UnusedMethodArgument
end
fail “TODO”
def do_something_else(unused)
end
raise NotImplementedError
def do_something(unused)
# bad
@example IgnoreNotImplementedMethods: false
end
raise AbstractMethodError
def do_something(unused)
# good
# with ‘NotImplementedExceptions: [’AbstractMethodError’]‘
@example IgnoreNotImplementedMethods: true
end
fail “TODO”
def do_something_else(unused)
end
raise NotImplementedError
def do_something(unused)
# good
# with default value of `NotImplementedExceptions: [’NotImplementedError’]‘
@example IgnoreNotImplementedMethods: true (default)
end
def do_something(unused)
# bad
@example IgnoreEmptyMethods: false
end
def do_something(unused)
# good
@example IgnoreEmptyMethods: true (default)
end
used
def do_something(used, unused: 42)
# good
@example AllowUnusedKeywordArguments: true
end
used
def do_something(used, unused: 42)
# bad
@example AllowUnusedKeywordArguments: false (default)
end
puts used
def some_method(used, _unused, _unused_but_allowed)
# good
end
puts used
def some_method(used, unused, _unused_but_allowed)
# bad
@example
Checks for unused method arguments.
def self.autocorrect_incompatible_with
def self.autocorrect_incompatible_with [Style::ExplicitBlockArgument] end
def self.joining_forces
def self.joining_forces VariableForce end
def allowed_exception_class?(node)
def allowed_exception_class?(node) return false unless node.const_type? allowed_class_names = Array(cop_config.fetch('NotImplementedExceptions', [])) allowed_class_names.include?(node.const_name) end
def autocorrect(corrector, node)
def autocorrect(corrector, node) UnusedArgCorrector.correct(corrector, processed_source, node) end
def check_argument(variable)
def check_argument(variable) return unless variable.method_argument? return if variable.keyword_argument? && cop_config['AllowUnusedKeywordArguments'] return if ignored_method?(variable.scope.node.body) super end
def ignored_method?(body)
def ignored_method?(body) (cop_config['IgnoreEmptyMethods'] && body.nil?) || (cop_config['IgnoreNotImplementedMethods'] && not_implemented?(body)) end
def message(variable)
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. " \ "If it's unnecessary, remove it." 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