KEMBAR78
[Fix #14605] Fix false positive for `Lint/EmptyInterpolation` when interpolation is inside a `%W` literal by dvandersluis · Pull Request #14606 · rubocop/rubocop · GitHub
Skip to content

Conversation

@dvandersluis
Copy link
Member

Interpolating an empty string inside a %W literal is a common way to include an empty string in the resulting array.

Fixes #14605.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

expect_correction(<<~RUBY)
["", one, two]
RUBY
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the same handling is needed not only for %W but also for %I.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thank you. Updated.

array_node = begin_node.each_ancestor(:array).first
return false unless array_node

array_node.source.start_with?('%W')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering %I as well, wouldn’t percent_literal? be more appropriate?

Suggested change
array_node.source.start_with?('%W')
array_node.percent_literal?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

percent_literal? allows for %w and %i too but since those cannot contain dstr/dsym, it should be okay.

…when interpolation is inside a `%W` literal
@koic koic merged commit 905c991 into rubocop:master Oct 18, 2025
22 checks passed
@koic
Copy link
Member

koic commented Oct 18, 2025

Thanks!

@dvandersluis dvandersluis deleted the issue/14605 branch October 18, 2025 17:01
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.

Lint/EmptyInterpolation false positive

2 participants