Skip to content

Commit

Permalink
Merge pull request #64 from inaka/harenson.407.max-function-length-ch…
Browse files Browse the repository at this point in the history
…eck-fails-unexpectedly

[Fix #407] Fix bug in max_function_length rule
  • Loading branch information
Brujo Benavides authored Oct 19, 2016
2 parents 7e50c77 + 7738e71 commit ad16894
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 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/
4 changes: 2 additions & 2 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
%% == Dependencies ==

{deps, [ {lager, "3.0.2"}
, {zipper, "1.0.0"}
, {zipper, "1.0.1"}
, {katana_code, "0.1.0"}
]}.

Expand All @@ -85,4 +85,4 @@

%% == Shell ==

{shell, [{apps, [sync]}]}.
{shell, [{apps, [sync]}]}.
13 changes: 12 additions & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
{"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">>,
{git,"https://github.com/inaka/zipper.git",
{ref,"47358be662a6749b5b0b932fc0aaad405f537a1c"}},
0}]}.
[
{pkg_hash,[
{<<"aleppo">>, <<"8DB14CF16BB8C263C14FF4C3F69F64D7C849D40888944F4204D2CA74F1114CEB">>},
{<<"goldrush">>, <<"349A351D17C71C2FDAA18A6C2697562ABE136FEC945F147B381F0CF313160228">>},
{<<"katana_code">>, <<"C34F3926A258D6BEACD8D21F140F3D47D175501936431C460B144339D5271A0B">>},
{<<"lager">>, <<"25DC81BC3659B62F5AB9BD073E97DDD894FC4C242019FCCEF96F3889D7366C97">>}]}
].
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 ad16894

Please sign in to comment.