Skip to content

Commit

Permalink
[Fix rubocop#2647] Allow xstr interpolations
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Jan 16, 2016
1 parent 6ec674c commit 28da640
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [#2630](https://github.com/bbatsov/rubocop/issues/2630): Take frozen string literals into account in `Style/MutableConstant`. ([@segiddins][])
* [#2642](https://github.com/bbatsov/rubocop/issues/2642): Support assignment via `||=` in `Style/MutableConstant`. ([@segiddins][])
* [#2646](https://github.com/bbatsov/rubocop/issues/2646): Fix auto-correcting assignment to a constant in `Style/ConditionalAssignment`. ([@segiddins][])
* [#2647](https://github.com/bbatsov/rubocop/issues/2647): Allow `xstr` interpolations in `Lint/LiteralInInterpolation`. ([@segiddins][])

### Changes

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/lint/literal_in_interpolation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def on_dstr(node)
final_node = begin_node.children.last
next unless final_node
next if special_keyword?(final_node)
next if final_node.xstr_type?
next unless final_node.literal?

add_offense(final_node, :expression)
Expand Down
5 changes: 5 additions & 0 deletions spec/rubocop/cop/lint/literal_in_interpolation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
expect(cop.offenses).to be_empty
end

it 'accepts interpolation of xstr' do
inspect_source(cop, '"this is #{`a`} silly"')
expect(cop.offenses).to be_empty
end

shared_examples 'literal interpolation' do |literal|
it "registers an offense for #{literal} in interpolation" do
inspect_source(cop, %("this is the \#{#{literal}}"))
Expand Down

0 comments on commit 28da640

Please sign in to comment.