Skip to content

Commit

Permalink
fix error message and clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
bormilan committed Oct 6, 2024
1 parent 6ad6086 commit abeda9a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 65 deletions.
49 changes: 4 additions & 45 deletions src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -948,62 +948,21 @@ max_function_clause_length(Config, Target, RuleConfig) ->
end,

ClauseLenInfos =
lists:append(
lists:map(PairFun, Functions0)),
lists:reverse(
lists:append(
lists:map(PairFun, Functions0))),

MaxLengthPred = fun({_, _, _, _, L}) -> L > MaxLength end,
ClauseLenMaxPairs = lists:filter(MaxLengthPred, ClauseLenInfos),

ResultFun =
fun({Name, Arity, StartPos, ClauseNumber, L}) ->
Info = [Name, Arity, ClauseNumber, L, MaxLength],
Info = [ClauseNumber, Name, Arity, L, MaxLength],
Msg = ?MAX_FUNCTION_CLAUSE_LENGTH,
elvis_result:new(item, Msg, Info, StartPos)
end,
lists:map(ResultFun, ClauseLenMaxPairs).

% IsClause = fun(Node) -> ktn_code:type(Node) == clause end,
% Clauses0 = elvis_code:find(IsClause, Root),
% FilterClause =
% fun(Line) ->
% (CountComments orelse not line_is_comment(Line))
% andalso (CountWhitespace orelse not line_is_whitespace(Line))
% end,
%
% PairClause =
% fun(ClauseNode, {Result, AccNum}) ->
% Name = ktn_code:attr(text, ClauseNode),
% {Min, Max} = node_line_limits(ClauseNode),
% FunLines = lists:sublist(Lines, Min, Max - Min + 1),
% FilteredLines = lists:filter(FilterClause, FunLines),
% L = length(FilteredLines),
% ClauseNumber = clause_num(Result, Name, AccNum + 1),
% StringClauseNumber = parse_clause_num(ClauseNumber),
% {[{Min, Name, StringClauseNumber, L} | Result], ClauseNumber}
% end,
% {ClauseLenInfos, _} = lists:foldl(PairClause, {[], 0}, Clauses0),

% MaxLengthPred = fun({_, _, _, L}) -> L > MaxLength end,
% ClauseLenMaxPairs = lists:filter(MaxLengthPred, ClauseLenInfos),
%
% ResultFun =
% fun({StartPos, Name, ClauseNumber, L}) ->
% Info = [ClauseNumber, Name, L, MaxLength],
% Msg = ?MAX_FUNCTION_CLAUSE_LENGTH,
% elvis_result:new(item, Msg, Info, StartPos)
% end,
% lists:map(ResultFun, ClauseLenMaxPairs).

% clause_num([], _, 1) ->
% 1;
% clause_num([{_, LastClauseName, _, _}], Name, 2) ->
% clause_num(LastClauseName, Name, 2);
% clause_num([{_, LastClauseName, _, _} | _], Name, AccNum) ->
% clause_num(LastClauseName, Name, AccNum);
% clause_num(LastClauseName, Name, AccNum) when LastClauseName =:= Name ->
% AccNum;
% clause_num(_, _, _) ->
% 1.
parse_clause_num(Num) when Num rem 100 >= 11, Num rem 100 =< 13 ->
integer_to_list(Num) ++ "th";
parse_clause_num(Num) when Num rem 10 == 1 ->
Expand Down
20 changes: 0 additions & 20 deletions test/style_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1145,26 +1145,6 @@ verify_max_function_length(Config) ->

-spec verify_max_function_clause_length(config()) -> any().
verify_max_function_clause_length(Config) ->
% I dont know where to put this
% Maybe I should make an eunit file
% "1st" = elvis_style:case_num([{a, "test_name1", c, d}], "test_name2", 2),
% "1st" = elvis_style:case_num([{a, "test_name1", c, d}], "test_name2", 6),
% "1st" = elvis_style:case_num([{a, "test_name1", c, d}], "test_name2", 62347),
%
% "2nd" = elvis_style:case_num([{a, "test_name1", c, d}], "test_name1", 2),
% "3rd" = elvis_style:case_num([{a, "test_name1", c, d}], "test_name1", 3),
% "4th" = elvis_style:case_num([{a, "test_name1", c, d}], "test_name1", 4),
% "5th" = elvis_style:case_num([{a, "test_name1", c, d}], "test_name1", 5),
%
% "55th" = elvis_style:case_num([{a, "test_name1", c, d}], "test_name1", 55),
% "19th" = elvis_style:case_num([{a, "test_name1", c, d}], "test_name1", 19),
% "567th" = elvis_style:case_num([{a, "test_name1", c, d}], "test_name1", 567),
% "100th" = elvis_style:case_num([{a, "test_name1", c, d}], "test_name1", 100),
%
% "101st" = elvis_style:case_num([{a, "test_name1", c, d}], "test_name1", 101),
% "72nd" = elvis_style:case_num([{a, "test_name1", c, d}], "test_name1", 72),
% "143rd" = elvis_style:case_num([{a, "test_name1", c, d}], "test_name1", 143),
% --------
Ext = proplists:get_value(test_file_ext, Config, "erl"),

PathFail = "fail_max_function_clause_length." ++ Ext,
Expand Down

0 comments on commit abeda9a

Please sign in to comment.