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 cdbe49b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 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/
11 changes: 10 additions & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{"1.1.0",
[{<<"aleppo">>,{pkg,<<"inaka_aleppo">>,<<"1.0.0">>},1},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.7">>},1},
{<<"katana_code">>,{pkg,<<"katana_code">>,<<"0.1.0">>},0},
{<<"lager">>,{pkg,<<"lager">>,<<"3.0.2">>},0},
{<<"zipper">>,{pkg,<<"zipper">>,<<"1.0.0">>},0}].
{<<"zipper">>,{pkg,<<"zipper">>,<<"1.0.0">>},0}]}.
[
{pkg_hash,[
{<<"aleppo">>, <<"8DB14CF16BB8C263C14FF4C3F69F64D7C849D40888944F4204D2CA74F1114CEB">>},
{<<"goldrush">>, <<"349A351D17C71C2FDAA18A6C2697562ABE136FEC945F147B381F0CF313160228">>},
{<<"katana_code">>, <<"C34F3926A258D6BEACD8D21F140F3D47D175501936431C460B144339D5271A0B">>},
{<<"lager">>, <<"25DC81BC3659B62F5AB9BD073E97DDD894FC4C242019FCCEF96F3889D7366C97">>},
{<<"zipper">>, <<"812CF95E93A025FAAAB1276B5789260A08CC129961DE226ADDC13EF56DF507B9">>}]}
].
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 cdbe49b

Please sign in to comment.