Skip to content

Code Formatter inconsistently changes indentation inside heredoc #7174

@rrrene

Description

@rrrene

Environment

  • Elixir & Erlang versions (elixir --version):

Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false]

Elixir 1.6.0-rc.0 (182c730) (compiled with OTP 19)

  • Operating system:

MacOS 10.12.6

Current behavior

When I create a file with a weirdly indented heredoc, like this

# test.ex
defmodule SampleModule do
  @my_module_attribute ~S'''
def fun() do
  42
end
  '''
end

and I use the formatter

mix format --check-equivalent test.ex

it does change the heredoc's content

# test.ex
defmodule SampleModule do
  @my_module_attribute ~S'''
  def fun() do
  42
  end
  '''
end

(note how the line containing 42 is not indented any more to the right)

Expected behavior

It should either indent the heredoc all at once

# test.ex
defmodule SampleModule do
  @my_module_attribute ~S'''
  def fun() do
    42
  end
  '''
end

... or leave the indentation as is.

Thx for taking the time to review this (and for the formatter in the first place!) 👏

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions