Skip to content

Commit 23cee9d

Browse files
committed
Keep if-s with else nil (explicit is better) and format the library
1 parent defc6c0 commit 23cee9d

File tree

7 files changed

+13
-11
lines changed

7 files changed

+13
-11
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ Other ways Styler can change your program:
123123
- [config file sorting](https://hexdocs.pm/styler/mix_configs.html#this-can-break-your-program)
124124
- and likely other ways. stay safe out there!
125125

126-
>>>>>>> upstream/main
127126
## Thanks & Inspiration
128127

129128
### [Sourceror](https://github.com/doorgan/sourceror/)

lib/style/blocks.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ defmodule Styler.Style.Blocks do
2525
* Credo.Check.Refactor.WithClauses
2626
"""
2727

28-
@behaviour Styler.Style
29-
3028
alias Styler.Style
3129
alias Styler.Zipper
3230

31+
@behaviour Styler.Style
32+
3333
defguardp is_negator(n) when elem(n, 0) in [:!, :not, :!=, :!==]
3434

3535
# case statement with exactly 2 `->` cases
@@ -144,8 +144,8 @@ defmodule Styler.Style.Blocks do
144144
{:cont, Zipper.replace(zipper, {:if, m, [head, [do_block]]}), ctx}
145145

146146
# drop `else: nil`
147-
[head, [do_block, {_, {:__block__, _, [nil]}}]] ->
148-
{:cont, Zipper.replace(zipper, {:if, m, [head, [do_block]]}), ctx}
147+
# [head, [do_block, {_, {:__block__, _, [nil]}}]] ->
148+
# {:cont, Zipper.replace(zipper, {:if, m, [head, [do_block]]}), ctx}
149149

150150
[head, [do_, else_]] ->
151151
if Style.max_line(do_) > Style.max_line(else_) do

lib/style/comment_directives.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ defmodule Styler.Style.CommentDirectives do
1515
`# styler:sort` maintains sorting of wordlists (by string comparison) and lists (string comparison of code representation)
1616
"""
1717

18-
@behaviour Styler.Style
19-
2018
alias Styler.Style
2119
alias Styler.Zipper
2220

21+
@behaviour Styler.Style
22+
2323
def run(zipper, ctx) do
2424
{zipper, comments} =
2525
ctx.comments

lib/zipper.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ defmodule Styler.Zipper do
178178
"""
179179
@spec prepend_siblings(zipper, [tree]) :: zipper
180180
def prepend_siblings({node, nil}, siblings), do: {:__block__, [], siblings ++ [node]} |> zip() |> down() |> rightmost()
181-
def prepend_siblings({tree, {l, p, r}}, siblings), do: {tree, {Enum.reverse(siblings, l), p , r}}
181+
def prepend_siblings({tree, {l, p, r}}, siblings), do: {tree, {Enum.reverse(siblings, l), p, r}}
182182

183183
@doc """
184184
Inserts the item as the right sibling of the node at this zipper, without

test/style/blocks_test.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,12 +734,14 @@ defmodule Styler.Style.BlocksTest do
734734
end
735735

736736
describe "if" do
737-
test "drops else nil" do
738-
assert_style("if a, do: b, else: nil", "if a, do: b")
737+
test "keeps else nil" do
738+
assert_style("if a, do: b, else: nil", "if a, do: b, else: nil")
739739

740740
assert_style("if a do b else nil end", """
741741
if a do
742742
b
743+
else
744+
nil
743745
end
744746
""")
745747

test/style/comment_directives_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
defmodule Styler.Style.CommentDirectivesTest do
1212
@moduledoc false
13+
1314
use Styler.StyleCase, async: true
1415

1516
describe "sort" do

test/zipper_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ defmodule StylerTest.ZipperTest do
7070
{1, {[], {{:foo, [], [1, 2]}, nil}, [2]}}
7171

7272
assert {{:., [], [:a, :b]}, [], [1, 2]} |> Zipper.zip() |> Zipper.down() ==
73-
{{:., [], [:a, :b]}, {[],{{{:., [], [:a, :b]}, [], [1, 2]}, nil}, [1, 2]}}
73+
{{:., [], [:a, :b]}, {[], {{{:., [], [:a, :b]}, [], [1, 2]}, nil}, [1, 2]}}
7474
end
7575
end
7676

0 commit comments

Comments
 (0)