nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: adobe/elixir-styler
Pull request #11 (2023-04-11 20:54:56)

Keep single-pipe function call rewrites on one line
test says it all =)

novaugust: will do! gonna add it on its own afterwards

Patch:
diff --git a/lib/style/pipes.ex b/lib/style/pipes.ex
index d80f311..b816496 100644
--- a/lib/style/pipes.ex
+++ b/lib/style/pipes.ex
@@ -28,7 +28,7 @@ defmodule Styler.Style.Pipes do
   # we're in a multi-pipe, so only need to fix pipe_start
   def run({{:|>, _, [{:|>, _, _} | _]}, _} = zipper, ctx), do: {:cont, zipper |> check_start() |> Zipper.next(), ctx}
   # this is a single pipe, since valid pipelines are consumed by the previous head
-  def run({{:|>, meta, [lhs, {fun, _, args}]}, _} = zipper, ctx) do
+  def run({{:|>, _, [lhs, {fun, meta, args}]}, _} = zipper, ctx) do
     if valid_pipe_start?(lhs) do
       # `a |> f(b, c)` => `f(a, b, c)`
       {:cont, Zipper.replace(zipper, {fun, meta, [lhs | args]}), ctx}


Test patch:
diff --git a/test/style/pipes_test.exs b/test/style/pipes_test.exs
index 5c00d54..0ab3652 100644
--- a/test/style/pipes_test.exs
+++ b/test/style/pipes_test.exs
@@ -175,6 +175,18 @@ defmodule Styler.Style.PipesTest do
       )
     end
 
+    test "keeps invocation on a single line" do
+      assert_style(
+        """
+        foo
+        |> bar(baz, bop, boom)
+        """,
+        """
+        bar(foo, baz, bop, boom)
+        """
+      )
+    end
+
     test "extracts blocks successfully" do
       assert_style(
         """
Repository: adobe/elixir-styler
Pull request #22 (2023-04-24 19:07:42)

Pipes: rewrite Enum.into oneliners to use Map.new instead
Realized we might as well ship it for all cases, not just when `Enum.map` comes ahead of it!


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6f17a0b..320d0b7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,10 +2,15 @@
 
 ## main
 
+## V0.4.1
+
+* `Pipes` rewrites `|> Enum.into(%{}[, mapper])` and `Enum.into(Map.new()[, mapper])` to `Map.new/1,2` calls
+
 ## v0.4.0
 
 ### Improvements
 
+
 * `Pipes` rewrites some two-step processes into one, fixing these credo issues in pipe chains:
     * `Credo.Check.Refactor.FilterCount`
     * `Credo.Check.Refactor.MapJoin`
diff --git a/lib/style/pipes.ex b/lib/style/pipes.ex
index 0739237..6b582d2 100644
--- a/lib/style/pipes.ex
+++ b/lib/style/pipes.ex
@@ -157,6 +157,16 @@ defmodule Styler.Style.Pipes do
     {:|>, [], [lhs, rhs]}
   end
 
+  defp optimize({:|>, meta, [lhs, {{:., dm, [{_, _, [:Enum]}, :into]}, _, [collectable]}]} = node) do
+    if empty_map?(collectable), do: {:|>, meta, [lhs, {{:., dm, [{:__aliases__, [], [:Map]}, :new]}, [], []}]}, else: node
+  end
+
+  defp optimize({:|>, meta, [lhs, {{:., dm, [{_, _, [:Enum]}, :into]}, _, [collectable, mapper]}]} = node) do
+    if empty_map?(collectable),
+      do: {:|>, meta, [lhs, {{:., dm, [{:__aliases__, [], [:Map]}, :new]}, [], [Style.delete_line_meta(mapper)]}]},
+      else: node
+  end
+
   defp optimize(node), do: node
 
   defp empty_map?({:%{}, _, []}), do: true


Test patch:
diff --git a/test/style/pipes_test.exs b/test/style/pipes_test.exs
index 2506bb7..c0bb6e6 100644
--- a/test/style/pipes_test.exs
+++ b/test/style/pipes_test.exs
@@ -93,12 +93,6 @@ defmodule Styler.Style.PipesTest do
         "Map.new(a, b)"
       )
 
-      assert_style("""
-      a
-      |> Enum.map(b)
-      |> Enum.into(%{}, c)
-      """)
-
       assert_style(
         """
         a
@@ -132,6 +126,42 @@ defmodule Styler.Style.PipesTest do
         """
       )
     end
+
+    test "into a new map" do
+      assert_style("a |> Enum.into(foo) |> b()")
+      assert_style("a |> Enum.into(%{}) |> b()", "a |> Map.new() |> b()")
+      assert_style("a |> Enum.into(Map.new) |> b()", "a |> Map.new() |> b()")
+
+      assert_style("a |> Enum.into(foo, mapper) |> b()")
+      assert_style("a |> Enum.into(%{}, mapper) |> b()", "a |> Map.new(mapper) |> b()")
+      assert_style("a |> Enum.into(Map.new, mapper) |> b()", "a |> Map.new(mapper) |> b()")
+
+      assert_style(
+        """
+        a
+        |> Enum.map(b)
+        |> Enum.into(%{}, c)
+        """,
+        """
+        a
+        |> Enum.map(b)
+        |> Map.new(c)
+        """
+      )
+
+      assert_style(
+        """
+        a
+        |> Enum.map(b)
+        |> Enum.into(Map.new, c)
+        """,
+        """
+        a
+        |> Enum.map(b)
+        |> Map.new(c)
+        """
+      )
+    end
   end
 
   describe "block starts" do
Repository: adobe/elixir-styler
Pull request #33 (2023-05-05 17:04:26)

Fix aliases using __MODULE__
This fixes an error that occurs when formatting a module with an alias on its submodules:

```elixir
defmodule Test do
  alias __MODULE_.{A, B}
end
```


Patch:
diff --git a/lib/style/module_directives.ex b/lib/style/module_directives.ex
index a8113ab..d7507a3 100644
--- a/lib/style/module_directives.ex
+++ b/lib/style/module_directives.ex
@@ -193,9 +193,13 @@ defmodule Styler.Style.ModuleDirectives do
   # =>
   # alias Foo.Bar
   # alias Foo.Baz
-  defp expand_directive({directive, _, [{{:., _, [{_, _, module}, :{}]}, _, right}]}),
+  defp expand_directive({directive, _, [{{:., _, [{:__aliases__, _, module}, :{}]}, _, right}]}),
     do: Enum.map(right, fn {_, meta, segments} -> {directive, meta, [{:__aliases__, [], module ++ segments}]} end)
 
+  # alias __MODULE__.{Bar, Baz}
+  defp expand_directive({directive, _, [{{:., _, [{:__MODULE__, _, _} = module, :{}]}, _, right}]}),
+    do: Enum.map(right, fn {_, meta, segments} -> {directive, meta, [{:__aliases__, [], [module | segments]}]} end)
+
   defp expand_directive(other), do: [other]
 
   defp reset_newlines([]), do: []


Test patch:
diff --git a/test/style/module_directives_test.exs b/test/style/module_directives_test.exs
index 7b0d57e..07d60d2 100644
--- a/test/style/module_directives_test.exs
+++ b/test/style/module_directives_test.exs
@@ -279,6 +279,18 @@ defmodule Styler.Style.ModuleDirectivesTest do
       end
     end
 
+    test "expands __MODULE__" do
+      assert_style(
+        """
+        alias __MODULE__.{B.D, A}
+        """,
+        """
+        alias __MODULE__.A
+        alias __MODULE__.B.D
+        """
+      )
+    end
+
     test "expands use but does not sort it" do
       assert_style(
         """
Repository: adobe/elixir-styler
Pull request #83 (2023-11-01 00:43:30)

fix: macros with only 1 block argument
This patch fixes a crash where macros with a single do block argument
that were being piped into a function.

Now, the following code transformation will occur instead of a crash:

```elixir
# from
foo do
  "hi"
end
|> IO.puts()

# to
IO.puts(
  foo do
    "hi"
  end
)
```

- [x] Please [sign Adobe's CLA](http://opensource.adobe.com/cla.html) if this is your first time contributing to an Adobe open source repo. Thanks!



Patch:
diff --git a/lib/style/pipes.ex b/lib/style/pipes.ex
index b54caca..ccb72ec 100644
--- a/lib/style/pipes.ex
+++ b/lib/style/pipes.ex
@@ -225,6 +225,8 @@ defmodule Styler.Style.Pipes do
   defp valid_pipe_start?({{:., _, _}, _, _}), do: false
   # variable
   defp valid_pipe_start?({variable, _, nil}) when is_atom(variable), do: true
+  # macro with single block argument
+  defp valid_pipe_start?({fun, _, [[{{:__block__, _, [:do]}, _}]]}) when is_atom(fun) and fun not in @blocks, do: true
   # 0-arity function_call()
   defp valid_pipe_start?({fun, _, []}) when is_atom(fun), do: true
   # function_call(with, args) or sigils. sigils are allowed, function w/ args is not


Test patch:
diff --git a/test/style/pipes_test.exs b/test/style/pipes_test.exs
index 8d33d9b..b962b84 100644
--- a/test/style/pipes_test.exs
+++ b/test/style/pipes_test.exs
@@ -12,6 +12,42 @@ defmodule Styler.Style.PipesTest do
   use Styler.StyleCase, async: true
 
   describe "big picture" do
+    test "macros with single do block argument" do
+      assert_style("""
+      IO.puts(
+        foo do
+          "foo"
+        end
+      )
+      """)
+
+      assert_style(
+        """
+        foo do
+          "foo"
+        end
+        |> IO.puts()
+        """,
+        """
+        IO.puts(
+          foo do
+            "foo"
+          end
+        )
+        """
+      )
+    end
+
+    test "macro with arg and do block" do
+      assert_style("""
+      "baz"
+      |> foo do
+        "foo"
+      end
+      |> IO.puts()
+      """)
+    end
+
     test "doesn't modify valid pipe" do
       assert_style("""
       a()
Repository: adobe/elixir-styler
Pull request #126 (2024-01-24 23:30:24)

Rewrite then/2 when function is a named function reference
- [x] Please [sign Adobe's CLA](http://opensource.adobe.com/cla.html) if this is your first time contributing to an Adobe open source repo. Thanks!

:wave: first and foremost, thanks for creating and maintaining styler! We use it in a large codebase where i stumbled over some occurrences of named function references passed into `Kernel.then/2`. I couldn't figure when that would be useful so I am opening this PR proposing to have it handled by styler. I've tested this change in our codebase but am happy to get any pointers on what i could've missed!

Let me know if you'd consider adding this to styler (or not! :)


Patch:
diff --git a/lib/style/pipes.ex b/lib/style/pipes.ex
index 87800e2..c470d90 100644
--- a/lib/style/pipes.ex
+++ b/lib/style/pipes.ex
@@ -142,6 +142,8 @@ defmodule Styler.Style.Pipes do
 
   # a |> fun => a |> fun()
   defp fix_pipe({:|>, m, [lhs, {fun, m2, nil}]}), do: {:|>, m, [lhs, {fun, m2, []}]}
+  # a |> then(&fun/1) |> c => a |> fun() |> c()
+  defp fix_pipe({:|>, m, [lhs, {:then, _, [{:&, _, [{:/, _, [{fun, m2, _}, _]}]}]}]}), do: {:|>, m, [lhs, {fun, m2, []}]}
   # Credo.Check.Readability.PipeIntoAnonymousFunctions
   # rewrite anonymous function invocation to use `then/2`
   # `a |> (& &1).() |> c()` => `a |> then(& &1) |> c()`


Test patch:
diff --git a/test/style/pipes_test.exs b/test/style/pipes_test.exs
index 5eee8ea..fcee097 100644
--- a/test/style/pipes_test.exs
+++ b/test/style/pipes_test.exs
@@ -498,6 +498,13 @@ defmodule Styler.Style.PipesTest do
       assert_style("a |> (fn x -> x end).() |> c", "a |> then(fn x -> x end) |> c()")
     end
 
+    test "rewrites then/2 when the passed function is a named function reference" do
+      assert_style("a |> then(&fun/1) |> c", "a |> fun() |> c()")
+      assert_style("a |> then(&DateTime.from_is8601/1) |> c", "a |> DateTime.from_is8601() |> c()")
+      assert_style("a |> then(&DateTime.from_is8601/1)", "DateTime.from_is8601(a)")
+      assert_style("a |> then(&fun(&1, d)) |> c", "a |> then(&fun(&1, d)) |> c()")
+    end
+
     test "adds parens to 1-arity pipes" do
       assert_style("a |> b |> c", "a |> b() |> c()")
     end
Repository: adobe/elixir-styler
Pull request #129 (2024-01-26 10:41:05)

fix: fix unary operators in pipes (fixes adobe#128)
I _guess_ that's the only operators that need tweaking? feel free to take over the PR :)

novaugust: Thanks! or, as josé would say: "💚 💙 💜 💛 ❤️"

all of the infix operators will have this issue too, but only some of those are implemented within Kernel so it'll take some weirdness to have a solution for everything (will probably only rewrite if it's a kernel infix/unary, and leave as-is in a `then` otherwise)

Patch:
diff --git a/lib/style/pipes.ex b/lib/style/pipes.ex
index 82fdf48..0baf93c 100644
--- a/lib/style/pipes.ex
+++ b/lib/style/pipes.ex
@@ -143,6 +143,12 @@ defmodule Styler.Style.Pipes do
     quote do: {:|>, _, [{:|>, _, [unquote(a), unquote(b)]}, unquote(c)]}
   end
 
+  # Unary operators needs to be expanded (#128)
+  defp maybe_wrap_unary({op, meta, []}) when op in ~w(- +)a,
+    do: {{:., meta, [{:__aliases__, meta, [:Kernel]}, op]}, meta, []}
+
+  defp maybe_wrap_unary(lhs), do: lhs
+
   # a |> fun => a |> fun()
   defp fix_pipe({:|>, m, [lhs, {fun, m2, nil}]}), do: {:|>, m, [lhs, {fun, m2, []}]}
   # a |> then(&fun/1) |> c => a |> fun() |> c()
@@ -150,10 +156,11 @@ defmodule Styler.Style.Pipes do
   # a |> then(&fun(&1, d)) |> c => a |> fun(d) |> c()
   defp fix_pipe({:|>, m, [lhs, {:then, _, [{:&, _, [{fun, m2, [{:&, _, _} | args]}]}]}]} = pipe) do
     rewrite = {fun, m2, args}
+
     # if `&1` is referenced more than once, we have to continue using `then`
     if rewrite |> Zipper.zip() |> Zipper.any?(&match?({:&, _, _}, &1)),
       do: pipe,
-      else: {:|>, m, [lhs, rewrite]}
+      else: {:|>, m, [lhs, maybe_wrap_unary(rewrite)]}
   end
 
   # Credo.Check.Readability.PipeIntoAnonymousFunctions


Test patch:
diff --git a/test/style/pipes_test.exs b/test/style/pipes_test.exs
index e3f3920..8adc2a4 100644
--- a/test/style/pipes_test.exs
+++ b/test/style/pipes_test.exs
@@ -505,6 +505,10 @@ defmodule Styler.Style.PipesTest do
       assert_style "a |> then(&fun(&1)) |> c", "a |> fun() |> c()"
       assert_style "a |> then(&fun(&1, d)) |> c", "a |> fun(d) |> c()"
 
+      # Unary operators
+      assert_style "a |> then(&(-&1)) |> c", "a |> Kernel.-() |> c()"
+      assert_style "a |> then(&(+&1)) |> c", "a |> Kernel.+() |> c()"
+
       assert_style "a |> then(&fun(d, &1)) |> c()"
       assert_style "a |> then(&fun(&1, d, %{foo: &1})) |> c()"
     end
Repository: adobe/elixir-styler
Pull request #164 (2024-05-10 10:28:49)

Fix piped `then` for complex expressions with division by one
An expression along the lines of `|> then(&(&1 * 2 / 1))` is currently being formatted as `|> (&1 * 2)` because the pattern match for single-arity functions is a bit too lax.

- [x] Please [sign Adobe's CLA](http://opensource.adobe.com/cla.html) if this is your first time contributing to an Adobe open source repo. Thanks!


Patch:
diff --git a/lib/style/pipes.ex b/lib/style/pipes.ex
index 1b2e269..b8a3b02 100644
--- a/lib/style/pipes.ex
+++ b/lib/style/pipes.ex
@@ -189,7 +189,7 @@ defmodule Styler.Style.Pipes do
 
   # a |> then(&fun/1) |> c => a |> fun() |> c()
   # recurses to add the `()` to `fun` as it gets unwound
-  defp fix_pipe({:|>, m, [lhs, {:then, _, [{:&, _, [{:/, _, [fun, {:__block__, _, [1]}]}]}]}]}),
+  defp fix_pipe({:|>, m, [lhs, {:then, _, [{:&, _, [{:/, _, [{_, _, nil} = fun, {:__block__, _, [1]}]}]}]}]}),
     do: fix_pipe({:|>, m, [lhs, fun]})
 
   # Credo.Check.Readability.PipeIntoAnonymousFunctions


Test patch:
diff --git a/test/style/pipes_test.exs b/test/style/pipes_test.exs
index 79ee89a..cb28cd3 100644
--- a/test/style/pipes_test.exs
+++ b/test/style/pipes_test.exs
@@ -501,6 +501,7 @@ defmodule Styler.Style.PipesTest do
     test "rewrites then/2 when the passed function is a named function reference" do
       assert_style "a |> then(&fun/1) |> c", "a |> fun() |> c()"
       assert_style "a |> then(&(&1 / 1)) |> c", "a |> Kernel./(1) |> c()"
+      assert_style "a |> then(&(&1 * 2 / 1)) |> c()"
       assert_style "a |> then(&fun/1)", "fun(a)"
       assert_style "a |> then(&fun(&1)) |> c", "a |> fun() |> c()"
       assert_style "a |> then(&fun(&1, d)) |> c", "a |> fun(d) |> c()"