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

In 1.57.0 Style/RedundantDoubleSplatHashBraces autocorrect doesn't seem right #12263

Closed
mikdiet opened this issue Oct 11, 2023 · 1 comment · Fixed by #12268
Closed

In 1.57.0 Style/RedundantDoubleSplatHashBraces autocorrect doesn't seem right #12263

mikdiet opened this issue Oct 11, 2023 · 1 comment · Fixed by #12268
Labels

Comments

@mikdiet
Copy link

mikdiet commented Oct 11, 2023

I updated to 1.57.0, and in my code I see new Style/RedundantDoubleSplatHashBraces offence, on the line:

logger.info('ClassToLog', event: 'perform', **attributes.merge({ worker_id: worker.id }))

Expected behavior

I expect something like

logger.info('ClassToLog', event: 'perform', worker_id: worker.id, **attributes)

Actual behavior

I got

logger.info('ClassToLog', event: 'perform', attributes, { worker_id: worker.id })

And it doesn't even look like correct ruby expression.

Steps to reproduce the problem

just run rubocop -a on above code

RuboCop version

 » bundle exec rubocop -V
1.57.0 (using Parser 3.2.2.4, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-darwin21]
  - rubocop-factory_bot 2.24.0
  - rubocop-graphql 1.4.0
  - rubocop-performance 1.19.1
  - rubocop-rails 2.21.2
  - rubocop-rspec 2.24.1
  - rubocop-sorbet 0.7.4
@mikdiet
Copy link
Author

mikdiet commented Oct 11, 2023

In fact, the correct expectation should be

logger.info('ClassToLog', event: 'perform', **attributes, worker_id: worker.id)

I think, as if we have worker_id key in attributes, it should be overridden.

@koic koic added the bug label Oct 12, 2023
koic added a commit to koic/rubocop that referenced this issue Oct 12, 2023
Fixes rubocop#12263.

This PR fixes false positives for `Style/RedundantDoubleSplatHashBraces`
when method call for no hash braced double splat receiver.

The code shown in rubocop#12263 is incompatible as shown below and is a false positive:

```ruby
def x(opts) = puts(opts)

h = {foo: :bar}

x(**h.merge(k: :h)) #=> {:foo=>:bar, :k=>:h}
x(k: :v, **h)       #=> {:k=>:v, :foo=>:bar}
```
bbatsov pushed a commit that referenced this issue Oct 12, 2023
Fixes #12263.

This PR fixes false positives for `Style/RedundantDoubleSplatHashBraces`
when method call for no hash braced double splat receiver.

The code shown in #12263 is incompatible as shown below and is a false positive:

```ruby
def x(opts) = puts(opts)

h = {foo: :bar}

x(**h.merge(k: :h)) #=> {:foo=>:bar, :k=>:h}
x(k: :v, **h)       #=> {:k=>:v, :foo=>:bar}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants