@@ -49,8 +49,10 @@ defmodule Credo.Check.Refactor.NegatedConditionsWithElse do
49
49
end
50
50
51
51
defp traverse ( { :if , meta , arguments } = ast , issues , issue_meta ) do
52
- if negated_condition? ( arguments ) && Credo.Code.Block . else_block? ( ast ) do
53
- new_issue = issue_for ( issue_meta , meta [ :line ] , "!" )
52
+ negator = negated_condition ( arguments )
53
+
54
+ if negator && Credo.Code.Block . else_block? ( ast ) do
55
+ new_issue = issue_for ( issue_meta , meta [ :line ] , negator )
54
56
55
57
{ ast , issues ++ [ new_issue ] }
56
58
else
@@ -62,27 +64,21 @@ defmodule Credo.Check.Refactor.NegatedConditionsWithElse do
62
64
{ ast , issues }
63
65
end
64
66
65
- defp negated_condition? ( arguments ) when is_list ( arguments ) do
66
- arguments |> List . first ( ) |> negated_condition? ( )
67
- end
68
-
69
- defp negated_condition? ( { :! , _meta , _arguments } ) do
70
- true
71
- end
67
+ defp negated_condition ( { :! , _ , _ } ) , do: "!"
72
68
73
- defp negated_condition? ( { :not , _meta , _arguments } ) do
74
- true
75
- end
69
+ defp negated_condition ( { :not , _ , _ } ) , do: "not"
76
70
77
71
# parentheses around the condition wrap it in a __block__
78
- defp negated_condition? ( { :__block__ , _meta , arguments } ) do
79
- negated_condition? ( arguments )
72
+ defp negated_condition ( { :__block__ , _ , arguments } ) do
73
+ negated_condition ( arguments )
80
74
end
81
75
82
- defp negated_condition? ( _ ) do
83
- false
76
+ defp negated_condition ( arguments ) when is_list ( arguments ) do
77
+ arguments |> List . first ( ) |> negated_condition ( )
84
78
end
85
79
80
+ defp negated_condition ( _ ) , do: nil
81
+
86
82
defp issue_for ( issue_meta , line_no , trigger ) do
87
83
format_issue (
88
84
issue_meta ,
0 commit comments