Skip to content

Commit

Permalink
fix no_match_in_condition
Browse files Browse the repository at this point in the history
  • Loading branch information
bormilan committed Oct 30, 2024
1 parent 979a586 commit 4228631
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,8 @@ no_match_in_condition(Config, Target, RuleConfig) ->
CaseNodes).

is_match_in_condition(Node) ->
ktn_code:type(Node) == case_expr andalso [] =/= elvis_code:find(fun is_match/1, Node).
(ktn_code:type(Node) == case_expr orelse ktn_code:type(Node) == block)
andalso lists:any(fun is_match/1, ktn_code:content(Node)).

is_match(Node) ->
ktn_code:type(Node) == match orelse ktn_code:type(Node) == maybe_match.
Expand Down
14 changes: 14 additions & 0 deletions test/examples/pass_no_match_in_condition2.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-module(pass_no_match_in_condition2).

-export([valid/1]).

valid(List) ->
case lists:all(fun ({K, V}) ->
Something = find:something(for, K),
check:something(V, Something)
end,
List)
of
true -> all_true;
false -> found_a_bad_one
end.
3 changes: 2 additions & 1 deletion test/style_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1638,9 +1638,10 @@ verify_no_match_in_condition(Config) ->

PassPath = "pass_no_match_in_condition." ++ Ext,
[] = elvis_core_apply_rule(Config, elvis_style, no_match_in_condition, #{}, PassPath),
PassPath2 = "pass_no_match_in_condition2." ++ Ext,
[] = elvis_core_apply_rule(Config, elvis_style, no_match_in_condition, #{}, PassPath2),

FailPath = "fail_no_match_in_condition." ++ Ext,

R = elvis_core_apply_rule(Config, elvis_style, no_match_in_condition, #{}, FailPath),
case Group of
beam_files ->
Expand Down

0 comments on commit 4228631

Please sign in to comment.