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
Metrics/ParameterLists
supports MaxOptionalParameters
config parameter
#9010
Metrics/ParameterLists
supports MaxOptionalParameters
config parameter
#9010
Conversation
I think the real problem is not a particular number of default arguments, but having any of them in the first place, and mixing them with keyword arguments. I'd just discourage their usage completely, but that's just me. @rubocop-hq/rubocop-core wha t do you think? |
There already a cop for too many positional arguments I believe, but the default maximum is super high (5?). My personal preference:
|
My intention with this cop was to avoid ugliness like def do_something(a = nil, b = nil, c = nil, d = nil)
end
do_something(nil, nil, nil, value) and more general def do_something(a = 1, b = 2, c = 3)
end
do_something(1, 2, 4) # you have to repeat default values for "a" and "b" to call with different "c"
agreed with mixing Feel free to close this if is not worth it. |
Btw, I was just reminded that we already have a cop |
As for keyword vs optional params - I'd love for us to have some cop that enforces more or less what @marcandre suggested, but I think that's orthogonal to @fatkodima's current suggestion. |
b6d6675
to
5db2a23
Compare
Style/TooManyDefaultArguments
copStyle/OptionalArguments
supports Max
config parameter
This is what I wanted 👍 So added that config. |
5db2a23
to
ee297eb
Compare
MSG = 'Optional arguments should appear at the end ' \ | ||
include ConfigurableMax | ||
|
||
MSG = 'Optional parameters should appear at the end ' \ | ||
'of the argument list.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argument -> parameter
Btw, I was thinking that we can also have this check in the other cops |
Forgot about its existence. |
Okay, let's go for it then. Sorry that I'm making you do so much extra work, I just have trouble remembering everything we've done so far. 😆 |
ee297eb
to
cfe1c78
Compare
cfe1c78
to
639494c
Compare
Style/OptionalArguments
supports Max
config parameterMetrics/ParameterLists
supports MaxOptionalParameters
config parameter
No worries. I have a lot of free time 😄 |
This is an implementation of https://rubystyle.guide/#keyword-arguments-vs-optional-arguments
Not sure if something like
IgnoredMethods
should be added - like for this https://github.com/rubocop-hq/rubocop/compare/master...fatkodima:too_many_default_arguments-cop?expand=1#diff-3b2d7d0e5589b3568a72de6447fa1095b2e9bae437f299ab43196979d0d50c01R36