Skip to content

Commit

Permalink
Merge pull request #302 from inaka/brujo.301.maybe_match
Browse files Browse the repository at this point in the history
Fix #301: Handle maybe matches
  • Loading branch information
elbrujohalcon authored Mar 2, 2023
2 parents 9b2b8ae + 2ce35f1 commit 0184e3b
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 44 deletions.
22 changes: 2 additions & 20 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
warn_exported_vars,
warn_missing_spec,
warn_untyped_record,
debug_info]}.
debug_info,
{feature, maybe_expr, enable}]}.

{profiles,
[{test,
Expand All @@ -28,25 +29,6 @@
{erl_opts, [nowarn_missing_spec, nowarn_export_all]},
{dialyzer, [{warnings, [no_return, unmatched_returns, error_handling]}]}]}]}.

%% == Common Test ==

{ct_compile_opts,
[warn_unused_vars,
warn_export_all,
warn_shadow_vars,
warn_unused_import,
warn_unused_function,
warn_bif_clash,
warn_unused_record,
warn_deprecated_function,
warn_obsolete_guard,
strict_validation,
warn_export_vars,
warn_exported_vars,
warn_missing_spec,
warn_untyped_record,
debug_info]}.

{ct_opts, [{sys_config, ["./config/test.config"]}, {logdir, "./logs"}, {verbose, true}]}.

%% == Cover ==
Expand Down
2 changes: 2 additions & 0 deletions src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,8 @@ check_parent_match(Zipper) ->
case ktn_code:type(Parent) of
match ->
zipper:down(ParentZipper) == Zipper;
maybe_match ->
zipper:down(ParentZipper) == Zipper;
_ ->
check_parent_match(ParentZipper)
end
Expand Down
4 changes: 0 additions & 4 deletions test/elvis_SUITE.erl
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
-module(elvis_SUITE).

-if(?OTP_RELEASE >= 23).

-behaviour(ct_suite).

-endif.

-export([all/0, init_per_suite/1, end_per_suite/1, chunk_fold_task/2]).
-export([rock_with_empty_map_config/1, rock_with_empty_list_config/1,
rock_with_incomplete_config/1, rock_with_list_config/1, rock_with_file_config/1,
Expand Down
4 changes: 2 additions & 2 deletions test/examples/consistent_generic_type_no_checks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@


% A function called any
-spec any() -> any.
-spec any() -> term(any).
any() -> any.

% A function called term
-spec term() -> term.
-spec term() -> any(term).
term() -> term.


Expand Down
13 changes: 13 additions & 0 deletions test/examples/fail_used_ignored_variable.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@

-elvis([{elvis_style, no_macros, #{allow => ['__']}}]).

-if(?OTP_RELEASE >= 25).

-export([no_used_ignored_vars_in_maybe/2]).

no_used_ignored_vars_in_maybe(One, _Two) ->
maybe
_ ?= do:something(One),
{ok, _Foo} ?= no:used_ignored_vars(here),
One
end.

-endif.

use_ignored_var(_One, Two) ->
Three = _One + Two,
case Three of
Expand Down
18 changes: 9 additions & 9 deletions test/examples/pass_no_nested_try_catch_elvis_attr.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

-dialyzer({nowarn_function, bad2/0}).

-ignore_xref([{maybe, throw, 1}]).
-ignore_xref([{it_may, throw, 1}]).
-ignore_xref([{a_function, that_deals, 2}]).

-export([
Expand All @@ -15,9 +15,9 @@
-elvis([{elvis_style, no_nested_try_catch, disable}]).
bad1() ->
try
maybe:throw(exception1),
it_may:throw(exception1),
try
maybe:throw(exception2),
it_may:throw(exception2),
"We are safe!"
catch
_:exception2 ->
Expand All @@ -30,16 +30,16 @@ bad1() ->

bad2() ->
try
maybe:throw(exception1),
it_may:throw(exception1),
try
maybe:throw(exception2),
it_may:throw(exception2),
"We are safe!"
catch
_:exception2 ->
"Oh, no! Exception #2"
end,
try
maybe:throw(exception3),
it_may:throw(exception3),
"We are safe!"
catch
_:exception3 ->
Expand All @@ -52,8 +52,8 @@ bad2() ->

good1() ->
try
maybe:throw(exception1),
maybe:throw(exception2),
it_may:throw(exception1),
it_may:throw(exception2),
"We are safe!"
catch
_:exception1 ->
Expand All @@ -64,7 +64,7 @@ good1() ->

good2() ->
try
maybe:throw(exception1),
it_may:throw(exception1),
a_function:that_deals(with, exception2),
"We are safe!"
catch
Expand Down
4 changes: 0 additions & 4 deletions test/project_SUITE.erl
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
-module(project_SUITE).

-if(?OTP_RELEASE >= 23).

-behaviour(ct_suite).

-endif.

-export([all/0, init_per_suite/1, end_per_suite/1]).
-export([verify_no_branch_deps/1, verify_hex_dep/1, verify_protocol_for_deps/1,
verify_old_config_format/1]).
Expand Down
6 changes: 1 addition & 5 deletions test/style_SUITE.erl
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
-module(style_SUITE).

-if(?OTP_RELEASE >= 23).

-behaviour(ct_suite).

-endif.

-export([all/0, groups/0, init_per_suite/1, end_per_suite/1, init_per_group/2,
end_per_group/2]).
-export([verify_function_naming_convention/1, verify_variable_naming_convention/1,
Expand Down Expand Up @@ -629,7 +625,7 @@ verify_used_ignored_variable(Config) ->
[#{line_num := _}, #{line_num := _}, #{line_num := _}, #{line_num := _}] =
elvis_core_apply_rule(Config, elvis_style, used_ignored_variable, #{}, Path);
erl_files ->
[#{line_num := 12}, #{line_num := 15}, #{line_num := 19}, #{line_num := 19}] =
[#{line_num := 25}, #{line_num := 28}, #{line_num := 32}, #{line_num := 32}] =
elvis_core_apply_rule(Config, elvis_style, used_ignored_variable, #{}, Path)
end,
[] =
Expand Down

0 comments on commit 0184e3b

Please sign in to comment.