Skip to content

Commit

Permalink
Don't pipe into Kernel.! when rewriting unless with pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
novaugust committed Sep 23, 2024
1 parent 79dce09 commit 4aa18ba
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
they can and will change without that change being reflected in Styler's semantic version.
## main

## 1.1.1

### Improvements

* `unless`: rewrite `unless a |> b |> c` as `unless !(a |> b() |> c())` rather than `unless a |> b() |> c() |> Kernel.!()` (h/t @gregmefford)

## 1.1.0

### Improvements
Expand Down
1 change: 0 additions & 1 deletion lib/style/blocks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ defmodule Styler.Style.Blocks do
defp invert({:===, m, [a, b]}), do: {:!==, m, [a, b]}
defp invert({:!, _, [condition]}), do: condition
defp invert({:not, _, [condition]}), do: condition
defp invert({:|>, m, _} = ast), do: {:|>, m, [ast, {{:., m, [Kernel, :!]}, m, []}]}
defp invert({:in, m, [_, _]} = ast), do: {:not, m, [ast]}
defp invert({_, m, _} = ast), do: {:!, [line: m[:line]], [ast]}
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Styler.MixProject do
use Mix.Project

# Don't forget to bump the README when doing non-patch version changes
@version "1.1.0"
@version "1.1.1"
@url "https://github.com/adobe/elixir-styler"

def project do
Expand Down
2 changes: 1 addition & 1 deletion test/style/blocks_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ defmodule Styler.Style.BlocksTest do
end

test "unless with pipes" do
assert_style "unless a |> b() |> c(), do: x", "if a |> b() |> c() |> Kernel.!(), do: x"
assert_style "unless a |> b() |> c(), do: x", "if !(a |> b() |> c()), do: x"
end

test "in" do
Expand Down

0 comments on commit 4aa18ba

Please sign in to comment.