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
Style/EmptyLiteral seems to want to repalce valid code with invalid code #9316
Comments
I am able to reproduce on rubocop However strangely, I cannot reproduce it on master and not sure if anything changed after |
That's very strange indeed because the file EVEN stranger, I tried switching back and forth between
I made a new temp directory, copied directly the
|
Okay, so if I create
|
Setting the
|
I've locally added this test below the one you linked and it fails as expected. context 'Ruby 2.7', :ruby27 do
it 'does not register an offense for Hash.new { _1[_2] = [] }' do
expect_no_offenses('test = Hash.new { _1[_2] = [] }')
end
end
|
…n using a numbered block `Hash.new { _1[_2] = [] }` is valid code but the cop was not parsing the numblock correctly when parsing ruby27. Now it treats both the above and `Hash.new { |h, k| h[k] = [] }` as valid statements.
[Fix #9316] Make `Style/EmptyLiteral` not register offense when using a numbered block
I have run into an issue with the
Style/EmptyLiteral
cop. It trys to replace validHash.new
code with invalid syntax when I run with autocorrect.Expected behavior
I expected RuboCop to not replace code in such a way that it breaks the rest of the file
Actual behavior
When run without autocorrect, it just flags that I should be using
{}
instead ofHash.new
Which already feels wrong as that is valid syntax. Maybe it's bad style though so I'm not sure on that front.
But if I run the above with autocorrect enabled, it breaks my code
Steps to reproduce the problem
Here are the contents of
empty_literal_test.rb
before running autocorrectRuboCop version
The text was updated successfully, but these errors were encountered: