diff --git a/src/elvis_style.erl b/src/elvis_style.erl index c9a57181..e52ba9f4 100644 --- a/src/elvis_style.erl +++ b/src/elvis_style.erl @@ -1094,7 +1094,8 @@ no_successive_maps(Config, Target, RuleConfig) -> Root = get_root(Config, Target, RuleConfig), Predicate = fun(Node) -> ktn_code:type(Node) == map end, ResultFun = result_node_line_fun(?NO_SUCCESSIVE_MAPS_MSG), - case elvis_code:find(Predicate, Root) of + FindOpts = #{mode => node, traverse => all}, + case elvis_code:find(Predicate, Root, FindOpts) of [] -> []; MapExprs -> diff --git a/test/examples/fail_no_successive_maps2.erl b/test/examples/fail_no_successive_maps2.erl new file mode 100644 index 00000000..9ced0bf8 --- /dev/null +++ b/test/examples/fail_no_successive_maps2.erl @@ -0,0 +1,41 @@ +-module(fail_no_successive_maps2). + +-export([test1/0, test2/0]). + +-if(?OTP_RELEASE<27). +test1() -> + _ = #{ + x => [ + #{a => b, c => d}, + #{a => b, c => d} % expected a warning here + #{a => b, c => d}, + #{a => b, c => d} + ] +}. +-else. +test1() -> + #{}. +-endif. + +-if(?OTP_RELEASE<27). +test2() -> + _ = #{ + map => #{ + x => [ + #{a => b, c => d}, + #{a => b, c => d} % expected a warning here + #{a => b, c => d}, + #{a => b, c => d} + ], + y => [ + #{a => b, c => d}, + #{a => b, c => d} % expected a warning here + #{a => b, c => d}, + #{a => b, c => d} + ] + } +}. +-else. +test2() -> + #{}. +-endif. diff --git a/test/style_SUITE.erl b/test/style_SUITE.erl index 45082004..08be829d 100644 --- a/test/style_SUITE.erl +++ b/test/style_SUITE.erl @@ -1358,13 +1358,19 @@ verify_no_successive_maps(Config) -> Module = fail_no_successive_maps, Path = atom_to_list(Module) ++ "." ++ Ext, + + Path2 = "fail_no_successive_maps2." ++ Ext, _ = case Group of beam_files -> [_, _, _] = - elvis_core_apply_rule(Config, elvis_style, no_successive_maps, #{}, Path); + elvis_core_apply_rule(Config, elvis_style, no_successive_maps, #{}, Path), + [_, _, _] = + elvis_core_apply_rule(Config, elvis_style, no_successive_maps, #{}, Path2); erl_files -> [#{line_num := 7}, #{line_num := 8}, #{line_num := 9}] = - elvis_core_apply_rule(Config, elvis_style, no_successive_maps, #{}, Path) + elvis_core_apply_rule(Config, elvis_style, no_successive_maps, #{}, Path), + [#{line_num := 10}, #{line_num := 26}, #{line_num := 32}] = + elvis_core_apply_rule(Config, elvis_style, no_successive_maps, #{}, Path2) end, [] =