Skip to content

Commit

Permalink
minor optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
novaugust committed Aug 7, 2024
1 parent 3769ffb commit 1661f41
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions lib/style/defs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,13 @@ defmodule Styler.Style.Defs do
first_line = meta[:line]
last_line = head_meta[:closing][:line]

cond do
# weird `def fun`, nothing else
is_nil(last_line) ->
{:skip, zipper, ctx}

# Already collapsed
first_line == last_line ->
{:skip, zipper, ctx}

# I just felt like this clause deserved a comment too. It's my favorite one
true ->
comments = Style.displace_comments(ctx.comments, first_line..last_line)
node = {def, meta, [Style.set_line(head, first_line)]}
{:skip, Zipper.replace(zipper, node), %{ctx | comments: comments}}
# Already collapsed or it's a bodyless/paramless `def fun`
if first_line == last_line || is_nil(last_line) do
{:skip, zipper, ctx}
else
comments = Style.displace_comments(ctx.comments, first_line..last_line)
node = {def, meta, [Style.set_line(head, first_line)]}
{:skip, Zipper.replace(zipper, node), %{ctx | comments: comments}}
end
end

Expand Down

0 comments on commit 1661f41

Please sign in to comment.