From 0781bb7009e388857142e892a1289dbc7c20d4fe Mon Sep 17 00:00:00 2001 From: bormilan Date: Thu, 3 Oct 2024 15:06:08 +0200 Subject: [PATCH] fix clause_num and parse_clause_num functions --- src/elvis_style.erl | 46 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/elvis_style.erl b/src/elvis_style.erl index feacaba1..eba681c4 100644 --- a/src/elvis_style.erl +++ b/src/elvis_style.erl @@ -926,8 +926,9 @@ max_function_clause_length(Config, Target, RuleConfig) -> FunLines = lists:sublist(Lines, Min, Max - Min + 1), FilteredLines = lists:filter(FilterClause, FunLines), L = length(FilteredLines), - ClauseNumber = case_num(Result, Name, AccNum + 1), - {[{Min, Name, ClauseNumber, L} | Result], AccNum + 1} + 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), @@ -942,28 +943,25 @@ max_function_clause_length(Config, Target, RuleConfig) -> end, lists:map(ResultFun, ClauseLenMaxPairs). -case_num([], _, 1) -> - "1st"; -case_num([{_, LastClauseName, _, _}], Name, 2) -> - case_num(LastClauseName, Name, 2); -case_num([{_, LastClauseName, _, _} | _], Name, AccNum) -> - case_num(LastClauseName, Name, AccNum); -case_num(LastClauseName, Name, AccNum) when LastClauseName =:= Name -> - lists:flatten(parse_case_num(AccNum)); -case_num(_, _, _) -> - "1st". - -parse_case_num(Num) -> - parse_case_num(Num, Num rem 10). - -parse_case_num(Num, 1) -> - io_lib:format("~pst", [Num]); -parse_case_num(Num, 2) -> - io_lib:format("~pnd", [Num]); -parse_case_num(Num, 3) -> - io_lib:format("~prd", [Num]); -parse_case_num(Num, _) -> - io_lib:format("~pth", [Num]). +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 10 == 1 -> + integer_to_list(Num) ++ "st"; +parse_clause_num(Num) when Num rem 10 == 2 -> + integer_to_list(Num) ++ "nd"; +parse_clause_num(Num) when Num rem 10 == 3 -> + integer_to_list(Num) ++ "rd"; +parse_clause_num(Num) -> + integer_to_list(Num) ++ "th". -spec max_function_length(elvis_config:config(), elvis_file:file(),