Skip to content

Commit fe643a1

Browse files
committed
Fix dstr handling.
1 parent a8775d0 commit fe643a1

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/rubocop/socketry/layout/consistent_blank_line_indentation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def on_new_investigation
5252

5353
processed_source.lines.each_with_index do |line, index|
5454
line_number = index + 1
55-
55+
5656
unless delta = indentation_deltas[line_number]
5757
# Skip this line (e.g., non-squiggly heredoc content):
5858
next
@@ -104,7 +104,7 @@ def walk_ast_for_indentation(node, deltas)
104104
end
105105
when :dstr
106106
if location = node.location
107-
if body = location.heredoc_body
107+
if location.is_a?(Parser::Source::Map::Heredoc) and body = location.heredoc_body
108108
if location.expression.source.start_with?("<<~")
109109
# Squiggly heredoc - indentation is significant, add deltas
110110
deltas[body.line] += 1

test/rubocop/socketry/layout/consistent_blank_line_indentation.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,15 @@
421421
expect(offenses).to be(:empty?)
422422
end
423423
end
424+
425+
with "an interpolated string" do
426+
let(:source) {"def foo\n\tname = 'world'\n\tputs \"Hello \#{name}\"\n\t\n\tputs 'done'\nend\n"}
427+
it "does not interfere with blank line indentation for interpolated strings" do
428+
processed_source = RuboCop::ProcessedSource.new(source, RUBY_VERSION.to_f)
429+
investigator = RuboCop::Cop::Commissioner.new([cop], [], raise_error: true)
430+
report = investigator.investigate(processed_source)
431+
offenses = report.offenses
432+
expect(offenses).to be(:empty?)
433+
end
434+
end
424435
end

0 commit comments

Comments
 (0)