Skip to content

Commit

Permalink
Merge pull request #12253 from knu/accept_empty_string_literal_interp…
Browse files Browse the repository at this point in the history
…olated_in_words_literal

Lint/LiteralInInterpolation: Accept an empty string literal interpolated in %W[]/%I[]
  • Loading branch information
koic committed Oct 10, 2023
2 parents ece1a95 + bc1b6a8 commit 11d412f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
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

0 comments on commit 11d412f

Please sign in to comment.