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

Ruby: Revise a rule related to optional arguments and keyword arguments #60

Closed
nekketsuuu opened this issue Apr 9, 2020 · 2 comments · Fixed by #61
Closed

Ruby: Revise a rule related to optional arguments and keyword arguments #60

nekketsuuu opened this issue Apr 9, 2020 · 2 comments · Fixed by #61

Comments

@nekketsuuu
Copy link
Contributor

nekketsuuu commented Apr 9, 2020

Rubocop 0.80.0 (released 2020-02-18) removed Style/BracesAroundHashParameters cop. rubocop/rubocop#7641 says the removal was because the curly braces may have the meaning since Ruby 2.7.

styleguide/.rubocop.yml

Lines 264 to 266 in 590bca6

# [SHOULD] Omit `{ }` of a hash literal, when put on the end of an argument list.
Style/BracesAroundHashParameters:
EnforcedStyle: no_braces

I think it's a good time to reconsider the above rule.

My opinion is:

Any thoughts?

@nekketsuuu
Copy link
Contributor Author

nekketsuuu commented Apr 9, 2020

How about...

[SHOULD] Distinguish between using a hash and using keyword arguments in method calls.

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)

The example above is a slightly modified version of rubocop/ruby-style-guide#788 (comment).

@nekketsuuu nekketsuuu changed the title Style/BracesAroundHashParameters is deprecated Ruby: Revise a rule related to optional arguments and keyword arguments Apr 9, 2020
@mame
Copy link
Contributor

mame commented Apr 10, 2020

Vote for the removal. The documents also looks great to me.

nekketsuuu added a commit to nekketsuuu/styleguide that referenced this issue Apr 13, 2020
nekketsuuu added a commit to nekketsuuu/styleguide that referenced this issue Apr 13, 2020
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

Successfully merging a pull request may close this issue.

2 participants