Skip to content

Commit 4b26464

Browse files
authored
- Fix quoted heredocs
2 parents 9e2617f + 6a2cd23 commit 4b26464

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

lib/bashly/concerns/indentation_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def set_heredoc_state(line)
3535
end
3636

3737
def extract_heredoc_marker(line)
38-
line =~ /<<-?\s*(\w+)/ ? $1 : nil
38+
line =~ /<<-?\s*['"]?(\w+)['"]?/ ? $1 : nil
3939
end
4040

4141
def heredoc_closed?(line)

spec/bashly/extensions/array_spec.rb

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,74 @@
4545
expect(subject.indent 2).to eq expected
4646
end
4747
end
48+
49+
context 'when the string contains a single quoted heredoc block' do
50+
subject do
51+
result = <<~SUBJECT
52+
function() {
53+
cat <<-'SOME_EOF_MARKER'
54+
not-indented
55+
indented-once
56+
indented-twice
57+
SOME_EOF_MARKER
58+
} # indented with function() start
59+
SUBJECT
60+
61+
result.lines
62+
end
63+
64+
let(:expected) do
65+
result = <<~SUBJECT
66+
function() {
67+
cat <<-'SOME_EOF_MARKER'
68+
not-indented
69+
indented-once
70+
indented-twice
71+
SOME_EOF_MARKER
72+
} # indented with function() start
73+
SUBJECT
74+
75+
result.lines
76+
end
77+
78+
it 'does not indent it but indents everything else' do
79+
expect(subject.indent 2).to eq expected
80+
end
81+
end
82+
83+
context 'when the string contains a double quoted heredoc block' do
84+
subject do
85+
result = <<~SUBJECT
86+
function() {
87+
cat <<-"SOME_EOF_MARKER"
88+
not-indented
89+
indented-once
90+
indented-twice
91+
SOME_EOF_MARKER
92+
} # indented with function() start
93+
SUBJECT
94+
95+
result.lines
96+
end
97+
98+
let(:expected) do
99+
result = <<~SUBJECT
100+
function() {
101+
cat <<-"SOME_EOF_MARKER"
102+
not-indented
103+
indented-once
104+
indented-twice
105+
SOME_EOF_MARKER
106+
} # indented with function() start
107+
SUBJECT
108+
109+
result.lines
110+
end
111+
112+
it 'does not indent it but indents everything else' do
113+
expect(subject.indent 2).to eq expected
114+
end
115+
end
48116
end
49117

50118
describe '#nonuniq' do

0 commit comments

Comments
 (0)