rubocop / rubocop/ruby-style-guide
Revise "No Braces Options Hash" rule
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 16.5k
- Forks
- 3.3k
- PR merge metrics
- No merged PRs in 30d
Description
https://github.com/rubocop-hq/ruby-style-guide#no-braces-opts-hash
See also https://github.com/rubocop-hq/rubocop/issues/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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked “No Braces Options Hash” section in the Ruby Style Guide and review the related RuboCop issue 7641. Revise the guidance and examples to distinguish hashes from keyword arguments under Ruby 2.7 and Ruby 3; done when both cases and their intended forms are documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100