Skip to content

Bare (<<) heredocs nested in squiggly (<<~) heredocs render invalid syntax/semantic changes #361

@reese

Description

@reese
  • Ruby version: 2.7.3
  • Rubyfmt git sha: ed99cc4

Input file

(I feel a little bad just writing this example)

class Foo
    def self.example
        p <<~FOO
          abc
          #{[1, 2].map do |n|
            <<BAR
    n is #{n}
BAR
    end
        }
        FOO
        .inspect
    end
end
Foo.example

Rubyfmt's output

class Foo
  def self.example
    p(
      <<~FOO.inspect
        abc
        #{[1, 2].map do |n|
                <<BAR
            n is #{n}
        BAR
              end}
      FOO
    )
  end
end

Foo.example

This breaks because

I mean, this is a pretty cursed way to write this, but this just came up as a cursed test case when I was working on #360. For bare heredocs, the closing BAR tag must be fully left-aligned, but we always bad the contents of squiggly heredocs with spaces no matter what. This also affects dash (<<-) heredocs as well, since it modifies the contents of the heredoc by adding too many spaces.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions