From 4aa18ba4fb7a2232bbe337fe43afff4e1387d67b Mon Sep 17 00:00:00 2001 From: Matt Enlow Date: Mon, 23 Sep 2024 13:42:41 -0600 Subject: [PATCH] Don't pipe into `Kernel.!` when rewriting unless with pipes --- CHANGELOG.md | 6 ++++++ lib/style/blocks.ex | 1 - mix.exs | 2 +- test/style/blocks_test.exs | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35791058..528daf90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/style/blocks.ex b/lib/style/blocks.ex index 9763d4d3..ce3a849c 100644 --- a/lib/style/blocks.ex +++ b/lib/style/blocks.ex @@ -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 diff --git a/mix.exs b/mix.exs index a74b30cf..edf369cb 100644 --- a/mix.exs +++ b/mix.exs @@ -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 diff --git a/test/style/blocks_test.exs b/test/style/blocks_test.exs index 7c140f05..fae1144b 100644 --- a/test/style/blocks_test.exs +++ b/test/style/blocks_test.exs @@ -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