-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AllowUnusedKeywordArguments option for UnusedMethodArgument #2304
Add AllowUnusedKeywordArguments option for UnusedMethodArgument #2304
Conversation
You're right, but since prepending an underscore to keyword arguments can change the semantics of calling the method, I think you should take the change even further. Either |
Btw, this is also related to simply checking whether the body of a method is empty. Guess we can have an option to suppress this check for empty method bodies (as we can presume they're just abstract). |
Probably this would be best. |
Keyword arguments are already ignored in auto-correct (see https://github.com/bbatsov/rubocop/blob/master/spec/rubocop/cop/lint/unused_method_argument_spec.rb#L310-L320), which is good news. That said, I feel that this is not enough, since if you have a project with a lot of subclassing and/or duck-types and keyword arguments, UnusedMethodArgument gives you a lot of false positives. I'd be happy to switch the default for |
Ah. Then I guess you can leave it as |
Yes, you're right--because in many cases those reports aren't actionable. Ready to merge, then? |
I'm OK with merging it, but the PR has to be rebased first. |
b29422b
to
83978dc
Compare
Sounds good--done! |
Add AllowUnusedKeywordArguments option for UnusedMethodArgument
Hi!
The UnusedMethodArgument cop is great for finding unused method arguments. One reason why people might have unused method arguments is when they are subclassing or adhering to a duck type. In those cases, RuboCop suggests adding an underscore to the method argument.
This is normally great advice for positional arguments, but in Ruby, underscores in front of keyword arguments result in run-time errors when you try to pass in those keyword arguments--the underscore doesn't have the same semantics as positional arguments.
The net result is that if you have a project with a lot of subclassing and/or duck-types and keyword arguments, UnusedMethodArgument gives you a lot of false positives.
This change provides an option called "AllowUnusedKeywordArguments" to address this by disabling the cop for unused keyword arguments.