Skip to content

Commit

Permalink
Merge pull request #269 from walrusVision/master
Browse files Browse the repository at this point in the history
Support for Rebar3 style deps
  • Loading branch information
Brujo Benavides committed Sep 7, 2015
2 parents 775763d + 69b34ba commit a8c7864
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
33 changes: 23 additions & 10 deletions src/elvis_project.erl
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,39 @@ get_rebar_deps(File) ->
[{deps, Deps}] -> Deps
end.

%% Rebar3
is_rebar_master_dep({_AppName, {_SCM, _Location, "master"}}) ->
true;
is_rebar_master_dep({_AppName, {_SCM, _Location, {branch, "master"}}}) ->
true;
%% Rebar2
is_rebar_master_dep({_AppName, _Vsn, {_SCM, _Location, "master"}}) ->
true;
is_rebar_master_dep({_AppName, _Vsn, {_SCM, _Location, {branch, "master"}}}) ->
true;
is_rebar_master_dep(_) ->
false.

is_rebar_not_git_dep({_AppName, {_SCM, Url, _Branch}}, Regex) ->
nomatch == re:run(Url, Regex, []);
is_rebar_not_git_dep({_AppName, _Vsn, {_SCM, Url, _Branch}}, Regex) ->
nomatch == re:run(Url, Regex, []).

rebar_dep_to_result({AppName, _, _}, Message, {IgnoreDeps, Regex}) ->
case lists:member(AppName, IgnoreDeps) of
true -> [];
false -> [elvis_result:new(item, Message, [AppName, Regex])]
end;
rebar_dep_to_result({AppName, _, _}, Message, IgnoreDeps) ->
case lists:member(AppName, IgnoreDeps) of
true -> [];
false -> [elvis_result:new(item, Message, [AppName])]
end.
rebar_dep_to_result({AppName, _}, Message, {IgnoreDeps, Regex}) ->
case lists:member(AppName, IgnoreDeps) of
true -> [];
false -> [elvis_result:new(item, Message, [AppName, Regex])]
end;
rebar_dep_to_result({AppName, _}, Message, IgnoreDeps) ->
case lists:member(AppName, IgnoreDeps) of
true -> [];
false -> [elvis_result:new(item, Message, [AppName])]
end;
rebar_dep_to_result({AppName, _, GitInfo}, Message, {IgnoreDeps, Regex}) ->
rebar_dep_to_result({AppName, GitInfo}, Message, {IgnoreDeps, Regex});
rebar_dep_to_result({AppName, _, GitInfo}, Message, IgnoreDeps) ->
rebar_dep_to_result({AppName, GitInfo}, Message, IgnoreDeps).



%%% erlang.mk
Expand Down
9 changes: 8 additions & 1 deletion test/examples/rebar.config.fail
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@
{meck, "0.*", {git, "https://github.com/eproxus/meck.git", "0.8.2"}},
{jiffy, "0.*", {git, "https://github.com/davisp/jiffy.git", "0.11.3"}},
{ibrowse, "4.*", {git, "https://github.com/cmullaparthi/ibrowse.git", "v4.1.1"}},
{aleppo, "0.*", {git, "https://github.com/inaka/aleppo.git", "master"}}
{aleppo, "0.*", {git, "https://github.com/inaka/aleppo.git", "master"}},

{lager, {git, "git://github.com/basho/lager.git", "2.0.0"}},
{getopt, {git, "git@github.com:jcomellas/getopt.git", {branch, "master"}}},
{meck, {git, "https://github.com/eproxus/meck.git", "0.8.2"}},
{jiffy, {git, "https://github.com/davisp/jiffy.git", "0.11.3"}},
{ibrowse, {git, "https://github.com/cmullaparthi/ibrowse.git", "v4.1.1"}},
{aleppo, {git, "https://github.com/inaka/aleppo.git", "master"}}
]
}.
{escript_name, "elvis"}.
Expand Down
16 changes: 8 additions & 8 deletions test/project_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ verify_no_deps_master_rebar(_Config) ->
Filename = "rebar.config.fail",
{ok, File} = elvis_test_utils:find_file(SrcDirs, Filename),

[_, _] = elvis_project:no_deps_master_rebar(ElvisConfig, File, #{}),
[_, _, _, _] = elvis_project:no_deps_master_rebar(ElvisConfig, File, #{}),

RuleConfig = #{ignore => [aleppo]},
[_] = elvis_project:no_deps_master_rebar(ElvisConfig, File, RuleConfig),
[_, _] = elvis_project:no_deps_master_rebar(ElvisConfig, File, RuleConfig),

RuleConfig1 = #{ignore => [aleppo, getopt]},
[] = elvis_project:no_deps_master_rebar(ElvisConfig, File, RuleConfig1).
Expand Down Expand Up @@ -147,16 +147,16 @@ verify_git_for_deps_rebar(_Config) ->
Filename = "rebar.config.fail",
{ok, File} = elvis_test_utils:find_file(SrcDirs, Filename),

[_, _] = elvis_project:git_for_deps_rebar(ElvisConfig, File, #{}),
[_, _, _, _] = elvis_project:git_for_deps_rebar(ElvisConfig, File, #{}),

RuleConfig = #{ignore => [getopt]},
[_] = elvis_project:git_for_deps_rebar(ElvisConfig, File, RuleConfig),
[_, _] = elvis_project:git_for_deps_rebar(ElvisConfig, File, RuleConfig),

RuleConfig1 = #{ignore => [getopt, lager]},
[] = elvis_project:git_for_deps_rebar(ElvisConfig, File, RuleConfig1),

RuleConfig2 = #{ignore => [meck], regex => "git@.*"},
[_, _, _, _] =
[_, _, _, _, _, _, _, _] =
elvis_project:git_for_deps_rebar(ElvisConfig, File, RuleConfig2).

-spec verify_protocol_for_deps_rebar(config()) -> any().
Expand All @@ -167,16 +167,16 @@ verify_protocol_for_deps_rebar(_Config) ->
Filename = "rebar.config.fail",
{ok, File} = elvis_test_utils:find_file(SrcDirs, Filename),

[_, _] = elvis_project:protocol_for_deps_rebar(ElvisConfig, File, #{}),
[_, _, _, _] = elvis_project:protocol_for_deps_rebar(ElvisConfig, File, #{}),

RuleConfig = #{ignore => [getopt]},
[_] = elvis_project:protocol_for_deps_rebar(ElvisConfig, File, RuleConfig),
[_, _] = elvis_project:protocol_for_deps_rebar(ElvisConfig, File, RuleConfig),

RuleConfig1 = #{ignore => [getopt, lager]},
[] = elvis_project:protocol_for_deps_rebar(ElvisConfig, File, RuleConfig1),

RuleConfig2 = #{ignore => [meck], regex => "git@.*"},
[_, _, _, _] =
[_, _, _, _, _, _, _, _] =
elvis_project:protocol_for_deps_rebar(ElvisConfig, File, RuleConfig2).

-spec verify_old_config_format(config()) -> any().
Expand Down

0 comments on commit a8c7864

Please sign in to comment.