From 4f241252a99df967dbf502133f7696fe66e88932 Mon Sep 17 00:00:00 2001 From: Matt Enlow Date: Tue, 13 Jun 2023 20:09:09 -0700 Subject: [PATCH] Fix: pipes + unpiping unquotes (Fixes #51) --- CHANGELOG.md | 4 ++++ lib/style/pipes.ex | 4 ++++ test/style/pipes_test.exs | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5efe61b..31973377 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## main +### Fixes + +* don't unpipe single-piped `unquote` expressions (h/t @elliottneilclark) + ## v0.7.12 ### Fixes diff --git a/lib/style/pipes.ex b/lib/style/pipes.ex index 1cf366ea..0e31e808 100644 --- a/lib/style/pipes.ex +++ b/lib/style/pipes.ex @@ -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]) diff --git a/test/style/pipes_test.exs b/test/style/pipes_test.exs index 12ff0700..7e4f3bf8 100644 --- a/test/style/pipes_test.exs +++ b/test/style/pipes_test.exs @@ -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)")