Skip to content

Commit

Permalink
ship struct update to map update changes after all
Browse files Browse the repository at this point in the history
  • Loading branch information
novaugust authored and kybishop committed Feb 20, 2025
1 parent dea14a7 commit a86664b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
7 changes: 3 additions & 4 deletions lib/style/deprecations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ defmodule Quokka.Style.Deprecations do
end
end

if Version.match?(System.version(), ">= 1.19.0-dev") do
# Struct update syntax was deprecated `%Foo{x | y} => %{x | y}`
defp style({:%, _, [_struct, {:%{}, _, [{:|, _, _}]} = update]}), do: update
end
# Struct update syntax is deprecated in 1.19
# `%Foo{x | y} => %{x | y}`
defp style({:%, _, [_struct, {:%{}, _, [{:|, _, _}]} = update]}), do: update

# For ranges where `start > stop`, you need to explicitly include the step
# Enum.slice(enumerable, 1..-2) => Enum.slice(enumerable, 1..-2//1)
Expand Down
12 changes: 4 additions & 8 deletions test/style/deprecations_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ defmodule Quokka.Style.DeprecationsTest do
end
end

test "struct update, deprecated in 1.19" do
assert_style "%Foo{widget | bar: :baz}", "%{widget | bar: :baz}"
end

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

Expand Down Expand Up @@ -158,12 +162,4 @@ defmodule Quokka.Style.DeprecationsTest do
assert_style "a |> x() |> :timer.seconds()"
end
end

describe "1.19+" do
@describetag skip: Version.match?(System.version(), "< 1.19.0-dev")

test "struct update" do
assert_style "%Foo{widget | bar: :baz}", "%{widget | bar: :baz}"
end
end
end
2 changes: 1 addition & 1 deletion test/style/pipes_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ defmodule Quokka.Style.PipesTest do

assert_style("""
def halt(exec, halt_message) do
%__MODULE__{exec | halted: true}
%{exec | halted: true}
|> put_halt_message(halt_message)
end
""")
Expand Down

0 comments on commit a86664b

Please sign in to comment.