Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #311 - fix no_match_in_condition reports a warning even when the condition includes a valid match #368

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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