-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 false negatives for Style/EmptyLiteral
#13173
Conversation
66a1f55
to
fe73343
Compare
current = array_with_index(node) ? 'Array[]' : 'Array.new' | ||
format(ARR_MSG, current: current) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update as below and adjust the specs to have more appropriate message?
current = array_with_index(node) ? 'Array[]' : 'Array.new' | |
format(ARR_MSG, current: current) | |
format(ARR_MSG, current: node.source) |
current = hash_with_index(node) ? 'Hash[]' : 'Hash.new' | ||
format(HASH_MSG, current: current) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
current = hash_with_index(node) ? 'Hash[]' : 'Hash.new' | |
format(HASH_MSG, current: current) | |
format(HASH_MSG, current: node.source) |
…ash[]`, `Array.new([])` and `Hash.new([])`
fe73343
to
34adfbe
Compare
expect_correction(<<~RUBY) | ||
test = [] | ||
RUBY | ||
context 'initializer resulting in an empty array literal' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
combined existing and new cases into shared examples for readability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for being considerate. However, as I mentioned in the comment below, shared_examples
do not always improve readability. Can you respect the existing spec descriptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in that particular case the shared examples are OK, given that we're essentially testing 6 times for the same thing.
expect_correction(<<~RUBY) | ||
test = [] | ||
RUBY | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shared_examples
don't always improve readability and reproducibility. Could you expand them into individual tests, as in the original specs?
@vlad-pisanov @bbatsov Why is |
@franzliedke That's an oversight that's fixed on |
See #13178 |
Improve
Style/EmptyLiteral
to detect other common ways of creating empty literals.Also: improve offense message by including the actual offense source
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.