rubocop / rubocop/ruby-style-guide

Revise "No Braces Options Hash" rule

Open
#788 0 comments 3 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.