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

Revise "No Braces Options Hash" rule #788

Open
pocke opened this issue Jan 13, 2020 · 0 comments
Open

Revise "No Braces Options Hash" rule #788

pocke opened this issue Jan 13, 2020 · 0 comments

Comments

@pocke
Copy link
Contributor

pocke commented Jan 13, 2020

https://github.com/rubocop-hq/ruby-style-guide#no-braces-opts-hash

See also rubocop/rubocop#7641

foo(kw: 1) and foo({kw: 1}) will have different meanings in Ruby 3. And Ruby warns them since Ruby 2.7 if it is used unexpectedly, and Ruby raises an argument error in Ruby 3.
But the style guide says "always omit the curly braces".

So I propose revising the guide.
I think the guide should mention both cases, Hash and keyword arguments.

For example:

def foo(a:, b:)
  p a, b
end

def bar(hash)
  p hash
end

# good
foo a: 1, b: 2
# good
bar({a: 1, b: 2})


# bad - foo expects keyword arguments, but it passes a Hash
foo({a: 1, b: 2})
# bad - bar expects a hash, but it passes keyword arguments
bar a: 1, b: 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant