Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
novaugust committed Sep 12, 2023
1 parent b37caf4 commit 094746e
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/style/single_node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,18 @@ defmodule Styler.Style.SingleNode do
defp style({:case, cm, [head, [{do_, arrows}]]}), do: {:case, cm, [head, [{do_, rewrite_arrows(arrows)}]]}
defp style({:fn, m, arrows}), do: {:fn, m, rewrite_arrows(arrows)}

# IF / UNLESS & NEGATION REWRITES
# Credo.Check.Refactor.UnlessWithElse
# if adding a negation to the if is incorrect, we'll remove it on the recurse =)
defp style({:unless, m, [{_, hm, _} = head, [{do_block, do_body}, {else_block, else_body}]]}) do
style({:if, m, [{:!, hm, [head]}, [{do_block, else_body}, {else_block, do_body}]]})
end
defp style({:unless, m, [{_, hm, _} = head, [{do_, do_body}, {else_, else_body}]]}),
do: style({:if, m, [{:!, hm, [head]}, [{do_, else_body}, {else_, do_body}]]})

# Credo.Check.Refactor.NegatedConditionsInUnless
defp style({:unless, m, [{negator, _, [expr]}, [{do_block, do_body}]]}) when negator in [:!, :not] do
style({:if, m, [expr, [{do_block, do_body}]]})
end
defp style({:unless, m, [{negator, _, [expr]}, [{do_, do_body}]]}) when negator in [:!, :not],
do: style({:if, m, [expr, [{do_, do_body}]]})

# Credo.Check.Refactor.NegatedConditionsWithElse
defp style({:if, m, [{negator, _, [expr]}, [{do_block, do_body}, {else_block, else_body}]]})
when negator in [:!, :not] do
style({:if, m, [expr, [{do_block, else_body}, {else_block, do_body}]]})
end
defp style({:if, m, [{negator, _, [expr]}, [{do_, do_body}, {else_, else_body}]]}) when negator in [:!, :not],
do: style({:if, m, [expr, [{do_, else_body}, {else_, do_body}]]})

defp style(node), do: node

Expand Down

0 comments on commit 094746e

Please sign in to comment.