Skip to content

Commit

Permalink
Allow for analysis under rebar3_hank
Browse files Browse the repository at this point in the history
(also add xref to the analysis)
  • Loading branch information
paulo-ferraz-oliveira committed Jul 26, 2021
1 parent f871c39 commit 0798801
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
otp_vsn: [20, 21, 22, 23, 24]
otp_vsn: [21, 22, 23, 24]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp_vsn}}
rebar3-version: '3.15'
- run: rebar3 hank
- run: rebar3 xref
- run: rebar3 dialyzer
- run: rebar3 ct
- run: rebar3 cover
Expand Down
15 changes: 14 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,17 @@
]}
]}.

{project_plugins, [rebar3_hex]}.
{project_plugins, [
rebar3_hex,
rebar3_hank
]}.

%% == hank ==

{hank, [
{ignore, [
{"test/**", unnecessary_function_arguments},
{"test/**", unused_macros},
{"test/**", unused_callbacks}
]}
]}.
12 changes: 12 additions & 0 deletions src/elvis_project.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
"Please check Elvis's GitHub repository to find out what the "
"new format is.").

% These are part of a non-declared "behaviour"
% The reason why we don't try to handle them with different arity is
% that arguments are ignored in different positions (1 and 3) so that'd
% probably be messier than to ignore the warning
-hank([{unnecessary_function_arguments, [
old_configuration_format/3,
no_deps_master_rebar/3,
no_deps_master_erlang_mk/3,
protocol_for_deps_rebar/3,
protocol_for_deps_erlang_mk/3
]}]).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Default values
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
9 changes: 0 additions & 9 deletions src/elvis_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@
-export_type([empty_rule_config/0]).
-export_type([ignorable/0]).

-define(LINE_LENGTH_MSG, "Line ~p is too long: ~s.").

-define(NO_TABS_MSG, "Line ~p has a tab at column ~p.").

-define(NO_SPACES_MSG, "Line ~p has a spaces at column ~p.").

-define(NO_TRAILING_WHITESPACE_MSG,
"Line ~b has ~b trailing whitespace characters.").

-define(INVALID_MACRO_NAME_REGEX_MSG,
"The macro named ~p on line ~p does not respect the format "
"defined by the regular expression '~p'.").
Expand Down
23 changes: 17 additions & 6 deletions src/elvis_text_style.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
-define(NO_TRAILING_WHITESPACE_MSG,
"Line ~b has ~b trailing whitespace characters.").

% These are part of a non-declared "behaviour"
% The reason why we don't try to handle them with different arity is
% that arguments are ignored in different positions (1 and 3) so that'd
% probably be messier than to ignore the warning
-hank([{unnecessary_function_arguments, [
no_trailing_whitespace/3,
no_spaces/3,
no_tabs/3,
line_length/3
]}]).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Default values
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -62,15 +73,15 @@ line_length(_Config, Target, RuleConfig) ->
[elvis_result:item()].
no_tabs(_Config, Target, _RuleConfig) ->
{Src, _} = elvis_file:src(Target),
elvis_utils:check_lines(Src, fun check_no_tabs/3, []).
elvis_utils:check_lines(Src, fun check_no_tabs/2, []).

-spec no_spaces(elvis_config:config(),
elvis_file:file(),
elvis_style:empty_rule_config()) ->
[elvis_result:item()].
no_spaces(_Config, Target, _RuleConfig) ->
{Src, _} = elvis_file:src(Target),
elvis_utils:check_lines(Src, fun check_no_spaces/3, []).
elvis_utils:check_lines(Src, fun check_no_spaces/2, []).

-type no_trailing_whitespace_config() :: #{ ignore => [module()],
ignore_empty_lines => boolean()
Expand Down Expand Up @@ -135,9 +146,9 @@ check_line_length(Line, Num, [Limit, Encoding]) ->

%% No Tabs

-spec check_no_tabs(binary(), integer(), [term()]) ->
-spec check_no_tabs(binary(), integer()) ->
no_result | {ok, elvis_result:item()}.
check_no_tabs(Line, Num, _Args) ->
check_no_tabs(Line, Num) ->
case binary:match(Line, <<"\t">>) of
nomatch ->
no_result;
Expand All @@ -150,9 +161,9 @@ check_no_tabs(Line, Num, _Args) ->

%% No Spaces

-spec check_no_spaces(binary(), integer(), [term()]) ->
-spec check_no_spaces(binary(), integer()) ->
no_result | {ok, elvis_result:item()}.
check_no_spaces(Line, Num, _Args) ->
check_no_spaces(Line, Num) ->
case re:run(Line, <<"^\t* ">>) of
nomatch ->
no_result;
Expand Down
13 changes: 10 additions & 3 deletions src/elvis_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% @doc Takes a binary that holds source code and applies
%% Fun to each line. Fun takes 3 arguments (the line
%% as a binary, the line number and the supplied Args) and
%% Fun to each line. Fun takes 2 or 3 arguments (the line
%% as a binary, the line number and the optional supplied Args) and
%% returns 'no_result' or {'ok', Result}.
-spec check_lines(binary(), fun(), term()) ->
[elvis_result:item()].
Expand All @@ -58,7 +58,14 @@ check_lines_with_context(Src, Fun, Args, Ctx) ->
check_lines([], _Fun, _Args, Results, _Num) ->
lists:flatten(lists:reverse(Results));
check_lines([Line | Lines], Fun, Args, Results, Num) ->
case Fun(Line, Num, Args) of
FunRes
= case is_function(Fun, 3) of
true ->
Fun(Line, Num, Args);
false ->
Fun(Line, Num)
end,
case FunRes of
{ok, Result} ->
check_lines(Lines, Fun, Args, [Result | Results], Num + 1);
no_result ->
Expand Down

0 comments on commit 0798801

Please sign in to comment.