Skip to content

Commit

Permalink
Rewrite Logger.warn to Logger.warning
Browse files Browse the repository at this point in the history
  • Loading branch information
novaugust committed Jun 22, 2023
1 parent 568a7c1 commit 86a9f22
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/style/single_node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ defmodule Styler.Style.SingleNode do
if Style.empty_map?(collectable), do: {{:., dm, [{:__aliases__, am, [:Map]}, :new]}, funm, [enum | rest]}, else: node
end

# Logger.warn -> Logger.warning
defp style({{:., dm, [{:__aliases__, am, [:Logger]}, :warn]}, funm, args}), do: {{:., dm, [{:__aliases__, am, [:Logger]}, :warning]}, funm, args}

# Remove parens from 0 arity funs (Credo.Check.Readability.ParenthesesOnZeroArityDefs)
defp style({def, dm, [{fun, funm, []} | rest]}) when def in ~w(def defp)a and is_atom(fun),
do: style({def, dm, [{fun, Keyword.delete(funm, :closing), nil} | rest]})
Expand Down
9 changes: 7 additions & 2 deletions test/style/single_node_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ defmodule Styler.Style.SingleNodeTest do
assert_style(~s|'"'|, ~s|~c"\\""|)
end

test "Logger.warn to Logger.warning" do
assert_style("Logger.warn(foo)", "Logger.warning(foo)")
assert_style("Logger.warn(foo, bar)", "Logger.warning(foo, bar)")
end

describe "def / defp" do
test "0-arity functions have parens removed" do
assert_style("def foo(), do: :ok", "def foo, do: :ok")
Expand Down Expand Up @@ -299,15 +304,15 @@ defmodule Styler.Style.SingleNodeTest do
case foo do
true -> :ok
false ->
Logger.warn("it's false")
Logger.warning("it's false")
nil
end
""",
"""
if foo do
:ok
else
Logger.warn("it's false")
Logger.warning("it's false")
nil
end
"""
Expand Down

0 comments on commit 86a9f22

Please sign in to comment.