Skip to content

Commit

Permalink
fix cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bormilan committed Oct 26, 2024
1 parent d1f6cfc commit 40d7985
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1135,32 +1135,19 @@ no_init_lists(Config, Target, RuleConfig) ->
andalso ktn_code:attr(arity, Node) == 1
end,

Init1Fun =
case elvis_code:find(IsInit1Function, Root) of
[] ->
[];
[Fun] ->
Fun
end,

FilterClauses =
fun(Clause) ->
[Attribute] = ktn_code:node_attr(pattern, Clause),
case is_list_node(Attribute) of
true ->
{true, ktn_code:attr(location, Clause)};
false ->
false
end
end,

Content = ktn_code:content(Init1Fun),
ListAttrClauses = lists:filtermap(FilterClauses, Content),
case length(ListAttrClauses) =:= length(Content) of
true ->
ListAttrClauses;
false ->
[]
case elvis_code:find(IsInit1Function, Root) of
[] ->
[];
[Init1Fun] ->
Content = ktn_code:content(Init1Fun),
ListAttrClauses =
lists:filtermap(fun(X) -> filter_list_clause_location(X) end, Content),
case length(ListAttrClauses) =:= length(Content) of
true ->
ListAttrClauses;
false ->
[]
end
end;
false ->
[]
Expand All @@ -1186,6 +1173,15 @@ is_relevant_behaviour(Root, RuleConfig) ->
end,
Behaviours)).

filter_list_clause_location(Clause) ->
[Attribute] = ktn_code:node_attr(pattern, Clause),
case is_list_node(Attribute) of
true ->
{true, ktn_code:attr(location, Clause)};
false ->
false
end.

is_list_node(#{type := cons}) ->
true;
is_list_node(#{type := nil}) ->
Expand Down

0 comments on commit 40d7985

Please sign in to comment.