Skip to content

Commit

Permalink
Address dialyzer warnings by changing the expression in test
Browse files Browse the repository at this point in the history
  • Loading branch information
jfacorro committed Dec 3, 2019
1 parent bc361f7 commit 19d46dd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
41 changes: 21 additions & 20 deletions src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -519,26 +519,27 @@ dont_repeat_yourself(Config, Target, RuleConfig) ->

Ignored = lists:member(ModuleName, IgnoreModules),

case Ignored orelse find_repeated_nodes(Root, MinComplexity) of
true when Ignored -> [];
[] -> [];
[_|_] = Nodes ->
LocationCat =
fun
({Line, Col}, "") ->
io_lib:format("(~p, ~p)", [Line, Col]);
({Line, Col}, Str) ->
io_lib:format("~s, (~p, ~p)", [Str, Line, Col])
end,
ResultFun =
fun([{Line, _} | _] = Locations) ->
LocationsStr = lists:foldl(LocationCat, "", Locations),
Info = [LocationsStr],
Msg = ?DONT_REPEAT_YOURSELF,
elvis_result:new(item, Msg, Info, Line)
end,
lists:map(ResultFun, Nodes)
end.
Nodes = case Ignored of
true -> [];
false -> find_repeated_nodes(Root, MinComplexity)
end,

LocationCat =
fun
({Line, Col}, "") ->
io_lib:format("(~p, ~p)", [Line, Col]);
({Line, Col}, Str) ->
io_lib:format("~s, (~p, ~p)", [Str, Line, Col])
end,
ResultFun =
fun([{Line, _} | _] = Locations) ->
LocationsStr = lists:foldl(LocationCat, "", Locations),
Info = [LocationsStr],
Msg = ?DONT_REPEAT_YOURSELF,
elvis_result:new(item, Msg, Info, Line)
end,

lists:map(ResultFun, Nodes).

-spec max_module_length(elvis_config:config(),
elvis_file:file(),
Expand Down
7 changes: 4 additions & 3 deletions test/style_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,12 @@ verify_dont_repeat_yourself(_Config) ->
PathFail = "fail_dont_repeat_yourself.erl",
{ok, FileFail} = elvis_test_utils:find_file(SrcDirs, PathFail),
RuleConfig5 = #{min_complexity => 5},
[_, _] =
elvis_style:dont_repeat_yourself(ElvisConfig, FileFail, RuleConfig5),
Res1 = elvis_style:dont_repeat_yourself(ElvisConfig, FileFail, RuleConfig5),
2 = length(Res1),

RuleConfig9 = #{min_complexity => 9},
[_] = elvis_style:dont_repeat_yourself(ElvisConfig, FileFail, RuleConfig9),
Res2 = elvis_style:dont_repeat_yourself(ElvisConfig, FileFail, RuleConfig9),
1 = length(Res2),

IgnoreRule = #{ignore => [fail_dont_repeat_yourself]},
[] = elvis_style:dont_repeat_yourself(ElvisConfig, FileFail, IgnoreRule),
Expand Down

0 comments on commit 19d46dd

Please sign in to comment.