elixir-lang / elixir

Elixir is a dynamic, functional language for building scalable and maintainable applications
https://elixir-lang.org/
Apache License 2.0
24.61k stars 3.38k forks source link

Code formatter: syntax error after formating heredoc with line break before terminator #6861

Closed amatalai closed 7 years ago

amatalai commented 7 years ago

Environment

Current behavior

Formatter output for this file

defmodule Example do
  @moduledoc false
  def text do
    """
    heredoc \
    """
  end
end

looks like this

defmodule Example do
  @moduledoc false
  def text do
    """
    heredoc """
  end
end

which ends as ** (SyntaxError) lib/example.ex:5: invalid location for heredoc terminator, please escape token or move it to its own line: """

Expected behavior

VERSION A

Don't remove line break from last line of heredoc

VERSION B

Don't allow to use line break in last line of heredoc like some other languages. In this case I would like to make PR, something like this: https://github.com/amatalai/elixir/blob/7817b634a9877368ac314b55aa4a8ab53e881cc4/lib/elixir/src/elixir_tokenizer.erl#L725-L727, but maybe with better message :)

josevalim commented 7 years ago

I will fix the formatter accordingly. Thank you!

amatalai commented 7 years ago

💚