diff --git a/CHANGELOG.md b/CHANGELOG.md index abf22d9f..8d01f6e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Improvements * alias: delete noop single-module aliases (`alias Foo`, #87, h/t @mgieger) +* pipes: recursively fix pipe starts (`f(g(h(x))) |> j()` => `x |> h() |> g() |> f() |> j()`, #94, h/t @tomjschuster) ## v0.10.3 diff --git a/lib/style/pipes.ex b/lib/style/pipes.ex index ad616c6b..35701a90 100644 --- a/lib/style/pipes.ex +++ b/lib/style/pipes.ex @@ -76,7 +76,7 @@ defmodule Styler.Style.Pipes do |> Zipper.insert_left(new_assignment) |> Zipper.left() else - {pipe, zmeta} + fix_pipe_start({pipe, zmeta}) end end end diff --git a/test/style/pipes_test.exs b/test/style/pipes_test.exs index 9cfda767..cc47008c 100644 --- a/test/style/pipes_test.exs +++ b/test/style/pipes_test.exs @@ -12,6 +12,10 @@ defmodule Styler.Style.PipesTest do use Styler.StyleCase, async: true describe "big picture" do + test "unnests multiple steps" do + assert_style("f(g(h(x))) |> j()", "x |> h() |> g() |> f() |> j()") + end + test "doesn't modify valid pipe" do assert_style(""" a()