Skip to content

with rewrite leaves empty with block behind in certain situations #184

Closed
@JesseHerrick

Description

@JesseHerrick

Hello! 👋 Thanks for this awesome Elixir tool! We encountered an interesting bug while applying Styler to our codebase. It seems that in certain situations, Styler leaves behind an empty with block wrapping the result.

I plan on looking into this myself when I have a bit of time, but I figured creating the issue would be helpful for tracking in any case.

Versions

  • Elixir: 1.16.0 and 1.17.2
  • Styler: Latest commit c16d3a91e489d043738e2b3bf5c12b6e6357e80c

Example Input

This test case can replicate the issue:

test "bug in with rewrite" do
  assert_style(
    """
    with foo <- do_stuff(value),
         {:ok, result} <- do_more_stuff(bar, baz) do
      {:ok, result}
    end
    """,
    """
    foo = do_stuff(value)
    do_more_stuff(bar, baz)
    """
  )
end

Stacktrace / Current Behaviour

     Styling produced unexpected results
     expected:
       foo = do_stuff(value)
       do_more_stuff(bar, baz)
     styled:
       foo = do_stuff(value)

       with do
         do_more_stuff(bar, baz)
       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