Skip to content

Formatting and check-formatted still not always consistent #3590

@dfalling

Description

@dfalling

Environment

  • Elixir version (elixir -v): 1.17.1
  • Phoenix version (mix deps): 1.7.18
  • Phoenix LiveView version (mix deps): 1.0.1
  • Operating system: macOS 15.0
  • Browsers you attempted to reproduce this bug on (the more the merrier): n/a
  • Does the problem persist after removing "assets/node_modules" and trying again? Yes/no: yes

Actual behavior

Formatter should format all code in a single pass that will then be accepted by mix format --check-formatted

(related to #3544)

Expected behavior

Formatter has to be run twice to get code to a state where it passes the check.

Example

starting code:

  def input(%{type: "select"} = assigns) do
    ~H"""
    <select>
      <option :if={@prompt} value="" class="dark:!text-white">{@prompt}</option>
      <!-- TODO: set color to below options somehow -->
      {IdoWeb.SlimSelectForm.options_for_select(@options, @value, "dark:!text-white")}
    </select>
    """
  end

with mix.format:

  def input(%{type: "select"} = assigns) do
    ~H"""
    <select>
      <option :if={@prompt} value="" class="dark:!text-white">{@prompt}</option>
      <!-- TODO: set color to below options somehow -->
      {IdoWeb.SlimSelectForm.options_for_select(@options, @value, "dark:!text-white")}

    </select>
    """
  end

(and mix format --check-formatted will error:

 396  396  |      {IdoWeb.SlimSelectForm.options_for_select(@options, @value, "dark:!text-white")}
 397  397  |
      398 +|
      399 +|
 398  400  |    </select>
 399  401  |    """
           |

If I run mix.format again, it will add those two extra lines that the check-formatted wants, and then everything passes.

If I remove the line with the TODO comment, the formatting works (and the blank lines before the </select> are removed.

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