From 093171ee42f293ba8ce48996833a6cf5abf618c9 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sun, 10 Nov 2024 12:56:10 +0000 Subject: [PATCH 01/10] Identify as branch, even if in `git_subdir` --- src/elvis_project.erl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/elvis_project.erl b/src/elvis_project.erl index 7efb0fd5..36ff7499 100644 --- a/src/elvis_project.erl +++ b/src/elvis_project.erl @@ -109,6 +109,8 @@ get_deps(File) -> %% @private is_branch_dep({_AppName, {_SCM, _Location, {branch, _}}}) -> true; +is_branch_dep({_AppName, {git_subdir, _Url, {branch, _}, _SubDir}}) -> + true; is_branch_dep({AppName, {raw, DepResourceSpecification}}) -> is_branch_dep({AppName, DepResourceSpecification}); %% Rebar2 From f2a62f6205b051fc7c42c1d13337a1825b445803 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sun, 10 Nov 2024 12:57:03 +0000 Subject: [PATCH 02/10] Move hex-specific comparison to "proper" place in code --- src/elvis_project.erl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/elvis_project.erl b/src/elvis_project.erl index 36ff7499..fbe29545 100644 --- a/src/elvis_project.erl +++ b/src/elvis_project.erl @@ -126,14 +126,15 @@ is_hex_dep(_AppName) when is_atom(_AppName) -> is_hex_dep({_AppName, _Vsn, {pkg, _PackageName}}) when is_atom(_AppName), is_list(_Vsn), is_atom(_PackageName) -> true; +is_hex_dep({_AppName, {pkg, _OtherName}}) + when is_atom(_AppName), is_atom(_OtherName) -> + true; is_hex_dep({_AppName, _Vsn}) when is_atom(_AppName), is_list(_Vsn) -> true; is_hex_dep(_) -> false. %% @private -is_not_git_dep({_AppName, {pkg, _OtherName}}, _Regex) -> - false; is_not_git_dep({_AppName, {_SCM, Url, _Branch}}, Regex) -> nomatch == re:run(Url, Regex, []); is_not_git_dep({AppName, {raw, DepResourceSpecification}}, Regex) -> From d6a9d52acabf0bc77ae46b0fd9df924203123d03 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sun, 10 Nov 2024 12:58:01 +0000 Subject: [PATCH 03/10] Ease identification of legacy formats --- src/elvis_project.erl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/elvis_project.erl b/src/elvis_project.erl index fbe29545..657ce5b8 100644 --- a/src/elvis_project.erl +++ b/src/elvis_project.erl @@ -139,6 +139,7 @@ is_not_git_dep({_AppName, {_SCM, Url, _Branch}}, Regex) -> nomatch == re:run(Url, Regex, []); is_not_git_dep({AppName, {raw, DepResourceSpecification}}, Regex) -> is_not_git_dep({AppName, DepResourceSpecification}, Regex); +%% Alternative formats, backwards compatible declarations is_not_git_dep({_AppName, {_SCM, Url}}, Regex) -> nomatch == re:run(Url, Regex, []); is_not_git_dep({_AppName, _Vsn, {_SCM, Url}}, Regex) -> From 15b9954496b8eefb2644f621c68fe5563ce723a7 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sun, 10 Nov 2024 12:59:00 +0000 Subject: [PATCH 04/10] Ease code analysis for future us --- src/elvis_project.erl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/elvis_project.erl b/src/elvis_project.erl index 657ce5b8..a9e87fae 100644 --- a/src/elvis_project.erl +++ b/src/elvis_project.erl @@ -111,6 +111,7 @@ is_branch_dep({_AppName, {_SCM, _Location, {branch, _}}}) -> true; is_branch_dep({_AppName, {git_subdir, _Url, {branch, _}, _SubDir}}) -> true; +%% Specific to plugin rebar_raw_resource is_branch_dep({AppName, {raw, DepResourceSpecification}}) -> is_branch_dep({AppName, DepResourceSpecification}); %% Rebar2 @@ -137,6 +138,7 @@ is_hex_dep(_) -> %% @private is_not_git_dep({_AppName, {_SCM, Url, _Branch}}, Regex) -> nomatch == re:run(Url, Regex, []); +%% Specific to plugin rebar_raw_resource is_not_git_dep({AppName, {raw, DepResourceSpecification}}, Regex) -> is_not_git_dep({AppName, DepResourceSpecification}, Regex); %% Alternative formats, backwards compatible declarations From f7b8dcef223d0e59183f431b80a2b0c4c06b75d9 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sun, 10 Nov 2024 12:59:23 +0000 Subject: [PATCH 05/10] Allow tag and ref in git_subdir, as per rebar3 --- src/elvis_project.erl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/elvis_project.erl b/src/elvis_project.erl index a9e87fae..3c21c6a2 100644 --- a/src/elvis_project.erl +++ b/src/elvis_project.erl @@ -138,6 +138,13 @@ is_hex_dep(_) -> %% @private is_not_git_dep({_AppName, {_SCM, Url, _Branch}}, Regex) -> nomatch == re:run(Url, Regex, []); +is_not_git_dep({_AppName, + {git_subdir, Url, {BranchTagOrRefType, _BranchTagOrRef}, _SubDir}}, + Regex) + when BranchTagOrRefType =:= branch; + BranchTagOrRefType =:= tag; + BranchTagOrRefType =:= ref -> + nomatch == re:run(Url, Regex, []); %% Specific to plugin rebar_raw_resource is_not_git_dep({AppName, {raw, DepResourceSpecification}}, Regex) -> is_not_git_dep({AppName, DepResourceSpecification}, Regex); @@ -147,8 +154,6 @@ is_not_git_dep({_AppName, {_SCM, Url}}, Regex) -> is_not_git_dep({_AppName, _Vsn, {_SCM, Url}}, Regex) -> nomatch == re:run(Url, Regex, []); is_not_git_dep({_AppName, _Vsn, {_SCM, Url, _Branch}}, Regex) -> - nomatch == re:run(Url, Regex, []); -is_not_git_dep({_AppName, {git_subdir, Url, {branch, _Branch}, _SubDir}}, Regex) -> nomatch == re:run(Url, Regex, []). %% @private From 37eade543b765518996361631a04fba15f3ff63d Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sun, 10 Nov 2024 13:05:52 +0000 Subject: [PATCH 06/10] Fix for backward compatibility case (with opts) --- src/elvis_project.erl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/elvis_project.erl b/src/elvis_project.erl index 3c21c6a2..8b2c4454 100644 --- a/src/elvis_project.erl +++ b/src/elvis_project.erl @@ -127,8 +127,7 @@ is_hex_dep(_AppName) when is_atom(_AppName) -> is_hex_dep({_AppName, _Vsn, {pkg, _PackageName}}) when is_atom(_AppName), is_list(_Vsn), is_atom(_PackageName) -> true; -is_hex_dep({_AppName, {pkg, _OtherName}}) - when is_atom(_AppName), is_atom(_OtherName) -> +is_hex_dep({_AppName, {pkg, _OtherName}}) when is_atom(_AppName), is_atom(_OtherName) -> true; is_hex_dep({_AppName, _Vsn}) when is_atom(_AppName), is_list(_Vsn) -> true; @@ -154,6 +153,11 @@ is_not_git_dep({_AppName, {_SCM, Url}}, Regex) -> is_not_git_dep({_AppName, _Vsn, {_SCM, Url}}, Regex) -> nomatch == re:run(Url, Regex, []); is_not_git_dep({_AppName, _Vsn, {_SCM, Url, _Branch}}, Regex) -> + nomatch == re:run(Url, Regex, []); +is_not_git_dep({_AppName, _Vsn, {_SCM, Url, {BranchTagOrRefType, _Branch}}, _Opts}, Regex) + when BranchTagOrRefType =:= branch; + BranchTagOrRefType =:= tag; + BranchTagOrRefType =:= ref -> nomatch == re:run(Url, Regex, []). %% @private From 9591fdb2bd065ea2594115df1722e9d0c35d4681 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sun, 10 Nov 2024 13:46:06 +0000 Subject: [PATCH 07/10] Fix test validations now that we match further --- test/project_SUITE.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/project_SUITE.erl b/test/project_SUITE.erl index 4980e9c6..e14d528b 100644 --- a/test/project_SUITE.erl +++ b/test/project_SUITE.erl @@ -41,16 +41,16 @@ verify_no_branch_deps(_Config) -> Filename = "rebar.config.fail", {ok, File} = elvis_test_utils:find_file(SrcDirs, Filename), - [_, _, _, _] = elvis_project:no_branch_deps(ElvisConfig, File, #{}), + [_, _, _, _, _] = elvis_project:no_branch_deps(ElvisConfig, File, #{}), RuleConfig = #{ignore => [jsx]}, - [_, _] = elvis_project:no_branch_deps(ElvisConfig, File, RuleConfig), + [_, _, _] = elvis_project:no_branch_deps(ElvisConfig, File, RuleConfig), RuleConfig1 = #{ignore => [jsx, getopt]}, - [] = elvis_project:no_branch_deps(ElvisConfig, File, RuleConfig1), + [_] = elvis_project:no_branch_deps(ElvisConfig, File, RuleConfig1), RuleConfig2 = #{ignore => [getopt]}, - [_, _] = elvis_project:no_branch_deps(ElvisConfig, File, RuleConfig2). + [_, _, _] = elvis_project:no_branch_deps(ElvisConfig, File, RuleConfig2). -spec verify_protocol_for_deps(config()) -> any(). verify_protocol_for_deps(_Config) -> From 130b8fdfbeb374d023cb0ecee2598caf9e9f794b Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sun, 10 Nov 2024 13:47:53 +0000 Subject: [PATCH 08/10] Include new file to test with --- test/examples/rebar3_2.config.success | 20 ++++++++++++++++++++ test/project_SUITE.erl | 11 ++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 test/examples/rebar3_2.config.success diff --git a/test/examples/rebar3_2.config.success b/test/examples/rebar3_2.config.success new file mode 100644 index 00000000..204b3e27 --- /dev/null +++ b/test/examples/rebar3_2.config.success @@ -0,0 +1,20 @@ +{deps, + [ + rebar, + {rebar, "1.0.0"}, + {rebar, {pkg, rebar_fork}}, + {rebar, "1.0.0", {pkg, rebar_fork}}, + {rebar, {git, "git://github.com/rebar/rebar.git", {branch, "main"}}}, + {rebar, {git, "https://github.com/rebar/rebar.git", {branch, "main"}}}, + {rebar, {git, "https://github.com/rebar/rebar.git", {tag, "1.0.0"}}}, + {rebar, {git, "https://github.com/rebar/rebar.git", {ref, "7f73b8d6"}}}, + {rebar, {hg, "https://github.com/rebar/rebar.git", {tag, "1.0.0"}}}, + {rebar, {git_subdir, "https://github.com/rebar/rebar.git", {branch, "main"}, "subdir"}}, + {rebar, {git_subdir, "https://github.com/rebar/rebar.git", {tag, "1.0.0"}, "sub/dir"}}, + {rebar, {git_subdir, "https://github.com/rebar/rebar.git", {ref, "7f73b8d6"}, "dir"}}, + %% Alternative formats, backwards compatible declarations + {rebar, {git, "git://github.com/rebar/rebar.git"}}, + {rebar, "1.0.*", {git, "git://github.com/rebar/rebar.git"}}, + {rebar, "1.0.*", {git, "git://github.com/rebar/rebar.git", "Rev"}}, + {rebar, ".*", {git, "git://github.com/rebar/rebar.git", {branch, "main"}}, [raw]} + ]}. diff --git a/test/project_SUITE.erl b/test/project_SUITE.erl index e14d528b..7a107851 100644 --- a/test/project_SUITE.erl +++ b/test/project_SUITE.erl @@ -85,10 +85,15 @@ verify_hex_dep(_Config) -> ElvisConfig = elvis_test_utils:config(rebar_config), SrcDirs = elvis_config:dirs(ElvisConfig), - Filename = "rebar3.config.success", - {ok, File} = elvis_test_utils:find_file(SrcDirs, Filename), + Filename1 = "rebar3.config.success", + {ok, File1} = elvis_test_utils:find_file(SrcDirs, Filename1), + + [] = elvis_project:protocol_for_deps(ElvisConfig, File1, #{}), + + Filename2 = "rebar3_2.config.success", + {ok, File2} = elvis_test_utils:find_file(SrcDirs, Filename2), - [] = elvis_project:protocol_for_deps(ElvisConfig, File, #{}). + [] = elvis_project:protocol_for_deps(ElvisConfig, File2, #{}). -spec verify_old_config_format(config()) -> any(). verify_old_config_format(_Config) -> From 4b411cd7db0451fff6f4297935349b3b7966c769 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Sun, 10 Nov 2024 13:51:10 +0000 Subject: [PATCH 09/10] Fix as per test results. --- src/elvis_project.erl | 2 ++ test/examples/rebar3_2.config.success | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/elvis_project.erl b/src/elvis_project.erl index 8b2c4454..91edcfbc 100644 --- a/src/elvis_project.erl +++ b/src/elvis_project.erl @@ -178,6 +178,8 @@ dep_to_result({AppName, _}, Message, IgnoreDeps) -> dep_to_result({AppName, _, GitInfo}, Message, {IgnoreDeps, Regex}) -> dep_to_result({AppName, GitInfo}, Message, {IgnoreDeps, Regex}); dep_to_result({AppName, _, GitInfo}, Message, IgnoreDeps) -> + dep_to_result({AppName, GitInfo}, Message, IgnoreDeps); +dep_to_result({AppName, _Vsn, GitInfo, _Opts}, Message, IgnoreDeps) -> dep_to_result({AppName, GitInfo}, Message, IgnoreDeps). %% Old config diff --git a/test/examples/rebar3_2.config.success b/test/examples/rebar3_2.config.success index 204b3e27..0bb04559 100644 --- a/test/examples/rebar3_2.config.success +++ b/test/examples/rebar3_2.config.success @@ -4,7 +4,6 @@ {rebar, "1.0.0"}, {rebar, {pkg, rebar_fork}}, {rebar, "1.0.0", {pkg, rebar_fork}}, - {rebar, {git, "git://github.com/rebar/rebar.git", {branch, "main"}}}, {rebar, {git, "https://github.com/rebar/rebar.git", {branch, "main"}}}, {rebar, {git, "https://github.com/rebar/rebar.git", {tag, "1.0.0"}}}, {rebar, {git, "https://github.com/rebar/rebar.git", {ref, "7f73b8d6"}}}, @@ -13,8 +12,8 @@ {rebar, {git_subdir, "https://github.com/rebar/rebar.git", {tag, "1.0.0"}, "sub/dir"}}, {rebar, {git_subdir, "https://github.com/rebar/rebar.git", {ref, "7f73b8d6"}, "dir"}}, %% Alternative formats, backwards compatible declarations - {rebar, {git, "git://github.com/rebar/rebar.git"}}, - {rebar, "1.0.*", {git, "git://github.com/rebar/rebar.git"}}, - {rebar, "1.0.*", {git, "git://github.com/rebar/rebar.git", "Rev"}}, - {rebar, ".*", {git, "git://github.com/rebar/rebar.git", {branch, "main"}}, [raw]} + {rebar, {git, "https://github.com/rebar/rebar.git"}}, + {rebar, "1.0.*", {git, "https://github.com/rebar/rebar.git"}}, + {rebar, "1.0.*", {git, "https://github.com/rebar/rebar.git", "Rev"}}, + {rebar, ".*", {git, "https://github.com/rebar/rebar.git", {branch, "main"}}, [raw]} ]}. From cdd09a4b2f1405cc321747698b54fb23e9ef5a6f Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Mon, 11 Nov 2024 23:10:08 +0000 Subject: [PATCH 10/10] protocol_for_deps: support git:// alongside https:// --- doc_rules/elvis_project/protocol_for_deps.md | 4 ++-- src/elvis_project.erl | 2 +- test/examples/rebar.config.fail | 4 ++-- test/examples/rebar3_2.config.success | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc_rules/elvis_project/protocol_for_deps.md b/doc_rules/elvis_project/protocol_for_deps.md index fbf58ee5..e9b85da6 100644 --- a/doc_rules/elvis_project/protocol_for_deps.md +++ b/doc_rules/elvis_project/protocol_for_deps.md @@ -8,7 +8,7 @@ This rule was called `protocol_for_deps_rebar` before ## Options - `regex :: string()`. - - default: `(https://.*|[0-9]+([.][0-9]+)*)`. + - default: `^(https://|git://|\\d+(\\.\\d+)*)`. ## Example @@ -21,5 +21,5 @@ This rule was called `protocol_for_deps_rebar` before - since [2.0.0](https://github.com/inaka/elvis_core/releases/tag/2.0.0) ```erlang -{elvis_project, protocol_for_deps, #{ regex => "(https://.*|[0-9]+([.][0-9]+)*)" }} +{elvis_project, protocol_for_deps, #{ regex => "^(https://|git://|\\d+(\\.\\d+)*)" }} ``` diff --git a/src/elvis_project.erl b/src/elvis_project.erl index 91edcfbc..39829b21 100644 --- a/src/elvis_project.erl +++ b/src/elvis_project.erl @@ -30,7 +30,7 @@ default(no_branch_deps) -> #{ignore => []}; default(protocol_for_deps) -> - #{ignore => [], regex => "(https://.*|[0-9]+([.][0-9]+)*)"}; + #{ignore => [], regex => "^(https://|git://|\\d+(\\.\\d+)*)"}; default(old_configuration_format) -> #{}. diff --git a/test/examples/rebar.config.fail b/test/examples/rebar.config.fail index f39e7bf2..80f574a3 100644 --- a/test/examples/rebar.config.fail +++ b/test/examples/rebar.config.fail @@ -21,7 +21,7 @@ {deps_dir, "deps"}. {deps, [ - {lager, "2.*", {git, "git://github.com/basho/lager.git", "2.0.0"}}, + {lager, "2.*", {git, "git2://github.com/basho/lager.git", "2.0.0"}}, {getopt, "0.*", {git, "git@github.com:jcomellas/getopt.git", {branch, "main"}}}, {meck, "0.*", {git, "https://github.com/eproxus/meck.git", "0.8.2"}}, {jiffy, "0.*", {git, "https://github.com/davisp/jiffy.git", "0.11.3"}}, @@ -30,7 +30,7 @@ {aleppo, "0.*", {git, "https://github.com/inaka/aleppo.git", "main"}}, {jsx, {raw, {git, "git@github.com:talentdeficit.git", {branch, "develop"}}}}, - {lager, {git, "git://github.com/basho/lager.git", "2.0.0"}}, + {lager, {git, "git2://github.com/basho/lager.git", "2.0.0"}}, {getopt, {git, "git@github.com:jcomellas/getopt.git", {branch, "main"}}}, {meck, {git, "https://github.com/eproxus/meck.git", "0.8.2"}}, {jiffy, {git, "https://github.com/davisp/jiffy.git", "0.11.3"}}, diff --git a/test/examples/rebar3_2.config.success b/test/examples/rebar3_2.config.success index 0bb04559..af1e43cb 100644 --- a/test/examples/rebar3_2.config.success +++ b/test/examples/rebar3_2.config.success @@ -4,12 +4,12 @@ {rebar, "1.0.0"}, {rebar, {pkg, rebar_fork}}, {rebar, "1.0.0", {pkg, rebar_fork}}, - {rebar, {git, "https://github.com/rebar/rebar.git", {branch, "main"}}}, + {rebar, {git, "git://github.com/rebar/rebar.git", {branch, "main"}}}, {rebar, {git, "https://github.com/rebar/rebar.git", {tag, "1.0.0"}}}, {rebar, {git, "https://github.com/rebar/rebar.git", {ref, "7f73b8d6"}}}, {rebar, {hg, "https://github.com/rebar/rebar.git", {tag, "1.0.0"}}}, {rebar, {git_subdir, "https://github.com/rebar/rebar.git", {branch, "main"}, "subdir"}}, - {rebar, {git_subdir, "https://github.com/rebar/rebar.git", {tag, "1.0.0"}, "sub/dir"}}, + {rebar, {git_subdir, "git://github.com/rebar/rebar.git", {tag, "1.0.0"}, "sub/dir"}}, {rebar, {git_subdir, "https://github.com/rebar/rebar.git", {ref, "7f73b8d6"}, "dir"}}, %% Alternative formats, backwards compatible declarations {rebar, {git, "https://github.com/rebar/rebar.git"}},