Skip to content
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

Cop to require keyword arguments instead of an options hash #2030

Closed
yob opened this issue Jul 10, 2015 · 2 comments
Closed

Cop to require keyword arguments instead of an options hash #2030

yob opened this issue Jul 10, 2015 · 2 comments

Comments

@yob
Copy link

yob commented Jul 10, 2015

Rails has made the following form of method signature quite popular, and we have lots of instances in our own code:

def foo(bar, options = {})
  ..
end

I'd like a cop to force these methods to be defined with optional keyword args instead:

def foo(bar, baz: true)
  ..
end

The second form is nicely self documenting and avoids a small amount of hash fetch code inside the method.

@bbatsov
Copy link
Collaborator

bbatsov commented Jul 10, 2015

Can't argue with this. I hate option hashes.

@yob
Copy link
Author

yob commented Jul 10, 2015

Cheers. It's probably not a good default - lots of library authors are likely still supporting Ruby versions without keyword arguments - but it'd be great for application code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants