Skip to content

Commit

Permalink
List.zip for good measure
Browse files Browse the repository at this point in the history
  • Loading branch information
novaugust committed Nov 19, 2024
1 parent 3ae7f5f commit 981b01e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/style/deprecations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ defmodule Styler.Style.Deprecations do

def run({node, meta}, ctx), do: {:cont, {style(node), meta}, ctx}

# Deprecated in 1.18
# rewrite patterns of `first..last = ...` to `first..last//_ = ...`
defp style({:=, m, [{:.., _, [_first, _last]} = range, rhs]}), do: {:=, m, [rewrite_range_match(range), rhs]}
defp style({:->, m, [[{:.., _, [_first, _last]} = range], rhs]}), do: {:->, m, [[rewrite_range_match(range)], rhs]}
Expand All @@ -25,6 +26,11 @@ defmodule Styler.Style.Deprecations do
defp style({def, dm, [{x, xm, params} | rest]}) when def in ~w(def defp)a and is_list(params),
do: {def, dm, [{x, xm, Enum.map(params, &rewrite_range_match/1)} | rest]}

# Deprecated in 1.18
# List.zip => Enum.zip
defp style({{:., dm_, [{:__aliases__, am, [:List]}, :zip]}, fm, arg}),
do: {{:., dm_, [{:__aliases__, am, [:Enum]}, :zip]}, fm, arg}

# Logger.warn => Logger.warning
# Started to emit warning after Elixir 1.15.0
defp style({{:., dm, [{:__aliases__, am, [:Logger]}, :warn]}, funm, args}),
Expand Down
6 changes: 6 additions & 0 deletions test/style/deprecations_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ defmodule Styler.Style.DeprecationsTest do
)
end

test "List.zip/1" do
assert_style "List.zip(foo)", "Enum.zip(foo)"
assert_style "foo |> List.zip |> bar", "foo |> Enum.zip() |> bar()"
assert_style "foo |> List.zip", "Enum.zip(foo)"
end

describe "1.16 deprecations" do
@describetag skip: Version.match?(System.version(), "< 1.16.0-dev")

Expand Down

0 comments on commit 981b01e

Please sign in to comment.