Skip to content

Commit

Permalink
fix unless do/else rewrites, closes #77
Browse files Browse the repository at this point in the history
  • Loading branch information
novaugust committed Sep 15, 2023
1 parent a284e40 commit 7cd2cdd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/style/single_node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ defmodule Styler.Style.SingleNode do

# IF / UNLESS & NEGATION REWRITES
# Credo.Check.Refactor.UnlessWithElse
defp style({:unless, m, [{_, hm, _} = head, [{do_, do_body}, {else_, else_body}]]}),
do: style({:if, m, [{:!, hm, [head]}, [{do_, else_body}, {else_, do_body}]]})
defp style({:unless, m, [{_, hm, _} = head, [_, _] = do_else]}),
do: style({:if, m, [{:!, hm, [head]}, do_else]})

# Credo.Check.Refactor.NegatedConditionsInUnless
defp style({:unless, m, [{negator, _, [expr]}, [{do_, do_body}]]}) when negator in [:!, :not],
Expand Down
12 changes: 6 additions & 6 deletions test/style/single_node_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,9 @@ defmodule Styler.Style.SingleNodeTest do
""",
"""
if a do
c
else
b
else
c
end
"""
)
Expand All @@ -551,9 +551,9 @@ defmodule Styler.Style.SingleNodeTest do
""",
"""
if a do
b
else
c
else
b
end
"""
)
Expand Down Expand Up @@ -636,9 +636,9 @@ defmodule Styler.Style.SingleNodeTest do
""",
"""
if true do
b
else
a
else
b
end
"""
)
Expand Down

0 comments on commit 7cd2cdd

Please sign in to comment.