Skip to content

Commit

Permalink
Fix: pipes + unpiping unquotes (Fixes #51)
Browse files Browse the repository at this point in the history
  • Loading branch information
novaugust committed Jun 14, 2023
1 parent d9f1712 commit 4f24125
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## main

### Fixes

* don't unpipe single-piped `unquote` expressions (h/t @elliottneilclark)

## v0.7.12

### Fixes
Expand Down
4 changes: 4 additions & 0 deletions lib/style/pipes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ defmodule Styler.Style.Pipes do
{{:|>, _, [{:|>, _, _}, _]}, _} = chain_zipper ->
{:cont, find_pipe_start(chain_zipper), ctx}

# don't un-pipe into unquotes, as some expressions are only valid as pipes
{{:|>, _, [_, {:unquote, _, [_]}]}, _} = single_pipe_unquote_zipper ->
{:cont, single_pipe_unquote_zipper, ctx}

{{:|>, _, [lhs, rhs]}, _} = single_pipe_zipper ->
{_, meta, _} = lhs
lhs = Style.set_line(lhs, meta[:line])
Expand Down
4 changes: 4 additions & 0 deletions test/style/pipes_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ defmodule Styler.Style.PipesTest do
end

describe "single pipe issues" do
test "allows unquote single pipes" do
assert_style("foo |> unquote(bar)")
end

test "fixes simple single pipes" do
assert_style("b(a) |> c()", "a |> b() |> c()")
assert_style("a |> f()", "f(a)")
Expand Down

1 comment on commit 4f24125

@elliottneilclark
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

Please sign in to comment.