Skip to content

Commit 8e93f4a

Browse files
authored
Merge pull request #251 from tomkonidas/add-support-for-negated-comparisons
Add support for negated comparisons
2 parents bb07d16 + 2132559 commit 8e93f4a

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

lib/style/single_node.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ defmodule Styler.Style.SingleNode do
4141
# refute nilly -> assert
4242
defp style({:refute, meta, [{:is_nil, _, [x]}]}), do: style({:assert, meta, [x]})
4343
defp style({:refute, meta, [{:==, _, [x, {:__block__, _, [nil]}]}]}), do: style({:assert, meta, [x]})
44+
45+
# negated comparisons
46+
defp style({:not, _, [{:==, m, xy}]}), do: {:!=, m, xy}
47+
defp style({:!, _, [{:==, m, xy}]}), do: {:!=, m, xy}
48+
4449
# boolean ops and assert hurt my brain.
4550
# the lone exception is `==` (... for now) ((uh, and the exception to the exception is when it's `== nil`, above))
4651
defp style({:refute, meta, [{:!=, m, xy}]}), do: style({:assert, meta, [{:==, m, xy}]})

test/style/single_node_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ defmodule Styler.Style.SingleNodeTest do
6767
assert_style "refute x > y", "assert x <= y"
6868
assert_style "refute x >= y", "assert x < y"
6969
end
70+
71+
test "negated comparisons" do
72+
assert_style "not (x == y)", "x != y"
73+
assert_style "!(x == y)", "x != y"
74+
assert_style "x != y"
75+
end
7076
end
7177

7278
test "string sigil rewrites" do

0 commit comments

Comments
 (0)