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

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

Open
reese opened this issue Nov 14, 2022 · 0 comments

Comments

@reese
Copy link
Collaborator

reese commented Nov 14, 2022

  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant