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

Lint/LiteralInInterpolation: Accept an empty string literal interpolated in %W[]/%I[] #12253

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12253](https://github.com/rubocop/rubocop/pull/12253): Fix `Lint/LiteralInInterpolation` to accept an empty string literal interpolated in words literal. ([@knu][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/literal_in_interpolation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def on_interpolation(begin_node)
# interpolation should not be removed if the expanded value
# contains a space character.
expanded_value = autocorrected_value(final_node)
return if in_array_percent_literal?(begin_node) && /\s/.match?(expanded_value)
return if in_array_percent_literal?(begin_node) && /\s|\A\z/.match?(expanded_value)

add_offense(final_node) do |corrector|
return if final_node.dstr_type? # nested, fixed in next iteration
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/lint/literal_in_interpolation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@
RUBY
end

it "accepts interpolation of an empty string literal in #{prefix}[]" do
expect_no_offenses(<<~RUBY)
#{prefix}[\#{""} is significant]
RUBY
end

it "accepts interpolation of a symbol literal with space in #{prefix}[]" do
expect_no_offenses(<<~RUBY)
#{prefix}[\#{:"this interpolation"} is significant]
Expand Down