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

Fix incorrect Style/HashSyntax autocorrection for assignment methods #11673

Merged
merged 1 commit into from Mar 7, 2023

Conversation

gsamokovarov
Copy link
Contributor

@gsamokovarov gsamokovarov commented Mar 7, 2023

In Ruby 3.1 and above, code like:

object.attr = {foo: foo}
                    ^^^ Omit the hash value.
pass

was incorrectly autocorrected to:

object.attr({foo:})
pass

The autocorrected code is valid Ruby but is semantically different. This may, and will, lead to subtle bugs in user codebases.

In Ruby 3.1 and above, code like:

```ruby
object.attr = {foo: foo}
                    ^^^ Omit the hash value.
pass
```

was incorrectly autocorrected to:

```ruby
object.attr({foo:})
pass
```

The autocorrected code is valid Ruby, but is semantically different.
This may and will lead to subtle bugs in user codebases.
@koic koic merged commit 6136ffd into rubocop:master Mar 7, 2023
@koic
Copy link
Member

koic commented Mar 7, 2023

Thanks!

@gsamokovarov gsamokovarov deleted the hash-syntax-in-assignment branch March 9, 2023 13:00
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 this pull request may close these issues.

None yet

2 participants