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

fix quoted here heredocs #626

Merged
merged 1 commit into from
Mar 16, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bashly/concerns/indentation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def set_heredoc_state(line)
end

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

def heredoc_closed?(line)
Expand Down
68 changes: 68 additions & 0 deletions spec/bashly/extensions/array_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,74 @@
expect(subject.indent 2).to eq expected
end
end

context 'when the string contains a single quoted heredoc block' do
subject do
result = <<~SUBJECT
function() {
cat <<-'SOME_EOF_MARKER'
not-indented
indented-once
indented-twice
SOME_EOF_MARKER
} # indented with function() start
SUBJECT

result.lines
end

let(:expected) do
result = <<~SUBJECT
function() {
cat <<-'SOME_EOF_MARKER'
not-indented
indented-once
indented-twice
SOME_EOF_MARKER
} # indented with function() start
SUBJECT

result.lines
end

it 'does not indent it but indents everything else' do
expect(subject.indent 2).to eq expected
end
end

context 'when the string contains a double quoted heredoc block' do
subject do
result = <<~SUBJECT
function() {
cat <<-"SOME_EOF_MARKER"
not-indented
indented-once
indented-twice
SOME_EOF_MARKER
} # indented with function() start
SUBJECT

result.lines
end

let(:expected) do
result = <<~SUBJECT
function() {
cat <<-"SOME_EOF_MARKER"
not-indented
indented-once
indented-twice
SOME_EOF_MARKER
} # indented with function() start
SUBJECT

result.lines
end

it 'does not indent it but indents everything else' do
expect(subject.indent 2).to eq expected
end
end
end

describe '#nonuniq' do
Expand Down
Loading