Skip to content

Commit c6056dd

Browse files
committed
Revert "Revert "rewrite then when value is first argument of named function""
This reverts commit 3a5cd94.
1 parent e02b09d commit c6056dd

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/style/pipes.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ defmodule Styler.Style.Pipes do
144144
defp fix_pipe({:|>, m, [lhs, {fun, m2, nil}]}), do: {:|>, m, [lhs, {fun, m2, []}]}
145145
# a |> then(&fun/1) |> c => a |> fun() |> c()
146146
defp fix_pipe({:|>, m, [lhs, {:then, _, [{:&, _, [{:/, _, [{fun, m2, _}, _]}]}]}]}), do: {:|>, m, [lhs, {fun, m2, []}]}
147+
# a |> then(&fun(&1, d)) |> c => a |> fun(d) |> c()
148+
defp fix_pipe({:|>, m, [lhs, {:then, _, [{:&, _, [{fun, m2, [{:&, _, _} | args]}]}]}]}),
149+
do: {:|>, m, [lhs, {fun, m2, args}]}
150+
147151
# Credo.Check.Readability.PipeIntoAnonymousFunctions
148152
# rewrite anonymous function invocation to use `then/2`
149153
# `a |> (& &1).() |> c()` => `a |> then(& &1) |> c()`

test/style/pipes_test.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,9 @@ defmodule Styler.Style.PipesTest do
502502
assert_style("a |> then(&fun/1) |> c", "a |> fun() |> c()")
503503
assert_style("a |> then(&DateTime.from_is8601/1) |> c", "a |> DateTime.from_is8601() |> c()")
504504
assert_style("a |> then(&DateTime.from_is8601/1)", "DateTime.from_is8601(a)")
505-
assert_style("a |> then(&fun(&1, d)) |> c", "a |> then(&fun(&1, d)) |> c()")
505+
assert_style("a |> then(&fun(&1)) |> c", "a |> fun() |> c()")
506+
assert_style("a |> then(&fun(&1, d)) |> c", "a |> fun(d) |> c()")
507+
assert_style("a |> then(&fun(d, &1)) |> c", "a |> then(&fun(d, &1)) |> c()")
506508
end
507509

508510
test "adds parens to 1-arity pipes" do

0 commit comments

Comments
 (0)