-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Rroblem with Style/HashSyntax cop in Ruby 3.1 #10359
Comments
In Ruby 3.1, the following code is equivalent. So, line breaked expression is the hash value. def some_method(token)
user = double :user, id: 42, token:
described_class.build(user)
end def some_method(token)
user = double :user, id: 42, token: described_class.build(user)
end This behavior is being considered in the following Ruby core issue.
This issue has been resolved by #10357. It will be included in the next release. |
I tested with version 1.25.0 and it looks like it still breaks the code with auto-correction even in safe mode. For example, it replaces build :user, token: token
SomeClass.new(true) with build :user, token:
SomeClass.new(true) Which breaks the code. Note that if there is Also, now it doesn't do auto-correction in a lot of safe cases even with |
Example when 1.25 doesn't report a warning where 1.24 did: p Hash[x: x] and def attrs(user, token)
{
user: user,
token: token
}
end |
…Syntax` Fixes rubocop#10359. This PR fixes a false positive and negative for `Style/HashSyntax` when using hash value omission. It resolves the lack of consideration for https://bugs.ruby-lang.org/issues/18396 and false positives for modifier forms.
Fixes #10359. This PR fixes a false positive and negative for `Style/HashSyntax` when using hash value omission. It resolves the lack of consideration for https://bugs.ruby-lang.org/issues/18396 and false positives for modifier forms.
Great, thank you 👍 |
This includes better compatibility with Ruby 3.1 due to rubocop/rubocop#10359 This release has been tested against: - Content Publisher - correctable RSpec/ExpectChange issues https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectChange - govuk_publishing_components - no issues - Search API - no issues - Whitehall - no issues
This includes better compatibility with Ruby 3.1 due to rubocop/rubocop#10359 This release has been tested against: - Content Publisher - correctable RSpec/ExpectChange issues https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExpectChange - govuk_publishing_components - no issues - Search API - no issues - Whitehall - no issues
When using ruby 3.1 hash syntax, I get the
Lint/UselessAssignment
cop warning.Expected behavior
No warnings.
Actual behavior
Steps to reproduce the problem
Version with brackets works as expected:
RuboCop version
Update:
It turns out that Ruby interprets the first one as
So technically this is not a false positive. However, this also means that auto-correction for Style/HashSyntax cop is not safe in this case. So probably this should be fixed somehow.
The text was updated successfully, but these errors were encountered: