Skip to content

Formatter settings ignored by pipe code action #558

@soundmonster

Description

@soundmonster

When the "Introduce pipe" code action is called, the file is reformatted but the line width setting from .formatter.exs is ignored.

Expected behavior:

  • Option 1: file is not reformatted on pipe code action
  • Option 2: file is reformatted following the rules in .formatter.exs

Observed behavior: line width setting from .formatter.exs is ignored when the "Introduce pipe" code action is applied, and the file is reformatted with a default line width (e.g. 80 characters) instead of the one specified in .formatter.exs (e.g. 120 characters).

Affected versions:

  • Expert 0.1.0
  • Editors tested:
    • NeoVim 0.11
    • Visual Studio Code 1.115.0 with official Expert LSP extension 0.3.1

Example

This is how it looks like:

Before

defmodule FormatterLineWidth do
  # first, put `line_length: 120` into `.formatter.exs`
  def function_to_apply_the_code_action_to() do
    Map.put(%{}, :foo, :bar)
    #        ⮤ Apply the code action "Introduce pipe" here
  end

  def function_that_should_be_a_oneliner() do
    some_function() |> some_function() |> some_function() |> some_function() |> some_function() |> some_function()
    # ⮤ this expression fits within 114 characters and should stay on one line after the code action is applied
    # The expression stays on one line when formatted with `mix format`, and also (e.g. on save) with Expert
  end

  def some_function(foo \\ 0), do: foo + 1
end

After

defmodule FormatterLineWidth do
  # first, put `line_length: 120` into `.formatter.exs`
  def function_to_apply_the_code_action_to() do
    %{} |> Map.put(:foo, :bar)
    #        ⮤ Apply the code action "Introduce pipe" here
  end

  def function_that_should_be_a_oneliner() do
    some_function()
    |> some_function()
    |> some_function()
    |> some_function()
    |> some_function()
    |> some_function()

    # ⮤ this expression fits within 114 characters and should stay on one line after the code action is applied
    # The expression stays on one line when formatted with `mix format`, and also (e.g. on save) with Expert
  end

  def some_function(foo \\ 0), do: foo + 1
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions