Skip to content

Commit

Permalink
change struct update deprecation to ex1.19+
Browse files Browse the repository at this point in the history
  • Loading branch information
novaugust committed Feb 20, 2025
1 parent a46c43f commit ceb827a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
43 changes: 27 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,16 @@ they can and will change without that change being reflected in Styler's semanti

## main

### Improvements

#### Ex1.17+

- Replace `:timer.units(x)` with the new `to_timeout(unit: x)` for `hours|minutes|seconds`
- Handle `, else: (_ -> x)` bugs introduced by `(_ -> x)` being termed a literal (#219, h/t @iamhassangm)
## 1.4

#### Ex1.18+
- A very nice change in alias lifting means Styler will make sure that your code is _using_ the aliases that it's specified.
- Shoutout to the smartrent folks for finding pipifying recursion issues
- Elixir 1.17 improvements and fixes
- Elixir 1.19-dev: delete struct updates

Delete deprecated struct update syntax in favor of map update syntax.
Read on for details.

```elixir
# This
%Struct{x | y}
# Styles to this
%{x | y}
```

**WARNING** Double check your diffs to make sure your variable is pattern matching against the same struct if you want to harness 1.18's type checking features. (#199, h/t @SteffenDE)
### Improvements

#### Alias Lifting

Expand All @@ -46,6 +37,26 @@ This release taught Styler to try just that little bit harder when doing alias l
C.bar()
C.baz()

#### Ex1.17+

- Replace `:timer.units(x)` with the new `to_timeout(unit: x)` for `hours|minutes|seconds`
- Handle `, else: (_ -> x)` bugs introduced by `(_ -> x)` being termed a literal (#219, h/t @iamhassangm)

#### Ex1.19+ (experimental)

1.19 deprecates struct update syntax in favor of map update syntax. Styler will do this update for you if you're on Elixir 1.19.0-dev or later.

```elixir
# This
%Struct{x | y}
# Styles to this
%{x | y}
```

**WARNING** Double check your diffs to make sure your variable is pattern matching against the same struct if you want to harness 1.18's type checking features.

A future version of Styler may be smart enough to do this check for you and perform the appropriate updates to the assignment location; no guarantees though. Track via #199, h/t @SteffenDE

### Fixes

- `pipes`: handle pipifying when the first arg is itself a pipe: `c(a |> b, d)` => `a |> b() |> c(d)` (#214, h/t @kybishop)
Expand Down
2 changes: 1 addition & 1 deletion lib/style/deprecations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ defmodule Styler.Style.Deprecations do
end
end

if Version.match?(System.version(), ">= 1.18.0-dev") do
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
Expand Down
4 changes: 2 additions & 2 deletions test/style/deprecations_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ defmodule Styler.Style.DeprecationsTest do
end
end

describe "1.18+" do
@describetag skip: Version.match?(System.version(), "< 1.18.0-dev")
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}"
Expand Down

0 comments on commit ceb827a

Please sign in to comment.