Skip to content

Commit

Permalink
[Fix #407] Fix bug in max_function_length rule
Browse files Browse the repository at this point in the history
  • Loading branch information
harenson committed Oct 17, 2016
1 parent 7e50c77 commit 8295332
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ rebar
.erlang.mk/
elvis.d
doc
rebar3.crashdump
rebar3.crashdump
.rebar3/
9 changes: 8 additions & 1 deletion src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,16 @@ no_debug_call(Config, Target, RuleConfig) ->
node_line_limits(FunctionNode) ->
Zipper = elvis_code:code_zipper(FunctionNode),
LineFun = fun(N) -> {L, _} = ktn_code:attr(location, N), L end,
% The first number in `lineNums' list is the location of the first
% line of the function. That's why we use it for the `Min' value.
LineNums = zipper:map(LineFun, Zipper),
% Last function's line
Max = lists:max(LineNums),
Min = lists:min(LineNums),
% If you use `lists:min/1' here, you will get weird results when using
% macros because most of the time macros are defined at the beginning of
% the module, but your function's first line could be in the middle or
% even at the end of the module.
[Min | _] = LineNums, % Min = first function's line
{Min, Max}.

-spec no_nested_try_catch(elvis_config:config(),
Expand Down

0 comments on commit 8295332

Please sign in to comment.