Current section
Files
Jump to
Current section
Files
lib/green/rules/linting/no_nil_else.ex
defmodule Green.Rules.Linting.NoNilElse do
@moduledoc """
This module removes `else` clauses that return `nil`.
"""
@behaviour Green.Rule
@impl true
def apply({forms, comments}, _opts) do
forms =
Macro.prewalk(forms, fn
{:if, context,
[
condition,
[
{{:__block__, ctx1, [:do]}, do_expression},
{{:__block__, _ctx2, [:else]}, {:__block__, _ctx, [nil]}}
]
]} ->
{:if, context,
[
condition,
[
{{:__block__, ctx1, [:do]}, do_expression}
]
]}
other ->
other
end)
{forms, comments}
end
end