Skip to content

Commit

Permalink
Merge branch 'main' into fix/protocol_for_deps
Browse files Browse the repository at this point in the history
  • Loading branch information
elbrujohalcon authored Nov 12, 2024
2 parents cdd09a4 + c19136f commit 292099e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
41 changes: 41 additions & 0 deletions test/examples/fail_no_successive_maps2.erl
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 8 additions & 2 deletions test/style_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,

[] =
Expand Down

0 comments on commit 292099e

Please sign in to comment.