Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
milmazz committed Aug 1, 2023
1 parent f46ae19 commit cd4a520
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
16 changes: 5 additions & 11 deletions lib/style/single_node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,13 @@ defmodule Styler.Style.SingleNode do
do: {{:., dm, [{:__aliases__, am, [:DateTime]}, :utc_now]}, funm, args}

if Version.match?(System.version(), ">= 1.15.0-dev") do
# Timex.{before?,after?} -> DateTime.{before?,after?}
defp style({{:., dm, [{:__aliases__, am, [:Timex]}, fun]}, funm, args}) when fun in [:before?, :after?],
do: {{:., dm, [{:__aliases__, am, [:DateTime]}, fun]}, funm, args}

# {DateTime,NaiveDateTime,Time,Date}.compare(a, b) == :lt -> {DateTime,NaiveDateTime,Time,Date}.before?(a, b)
defp style({:==, _, [{{:., dm, [{:__aliases__, am, [mod]}, :compare]}, funm, args}, {:__block__, _, [:lt]}]})
when mod in ~w[DateTime NaiveDateTime Time Date]a,
do: {{:., dm, [{:__aliases__, am, [mod]}, :before?]}, funm, args}

# {DateTime,NaiveDateTime,Time,Date}.compare(a, b) == :gt -> {DateTime,NaiveDateTime,Time,Date}.after?(a, b)
defp style({:==, _, [{{:., dm, [{:__aliases__, am, [mod]}, :compare]}, funm, args}, {:__block__, _, [:gt]}]})
when mod in ~w[DateTime NaiveDateTime Time Date]a,
do: {{:., dm, [{:__aliases__, am, [mod]}, :after?]}, funm, args}
defp style({:==, _, [{{:., dm, [{:__aliases__, am, [mod]}, :compare]}, funm, args}, {:__block__, _, [result]}]})
when mod in ~w[DateTime NaiveDateTime Time Date]a and result in [:lt, :gt] do
fun = if result == :lt, do: :before?, else: :after?
{{:., dm, [{:__aliases__, am, [mod]}, fun]}, funm, args}
end
end

# Remove parens from 0 arity funs (Credo.Check.Readability.ParenthesesOnZeroArityDefs)
Expand Down
8 changes: 0 additions & 8 deletions test/style/single_node_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ defmodule Styler.Style.SingleNodeTest do
end

if Version.match?(System.version(), ">= 1.15.0-dev") do
test "Timex.before?(a, b) -> DateTime.before?(a, b)" do
assert_style("Timex.before?(a, b)", "DateTime.before?(a, b)")
end

test "Timex.after?(a, b) -> DateTime.after?(a, b)" do
assert_style("Timex.after?(a, b)", "DateTime.after?(a, b)")
end

test "{DateTime,NaiveDateTime,Time,Date}.compare to {DateTime,NaiveDateTime,Time,Date}.before?" do
assert_style("DateTime.compare(foo, bar) == :lt", "DateTime.before?(foo, bar)")
assert_style("NaiveDateTime.compare(foo, bar) == :lt", "NaiveDateTime.before?(foo, bar)")
Expand Down

0 comments on commit cd4a520

Please sign in to comment.