From 9ea27a8af2ec9135b49ab7cb67a5e5a5d8bc14d6 Mon Sep 17 00:00:00 2001 From: AdmiringWorm Date: Thu, 5 Dec 2024 15:06:41 +0100 Subject: [PATCH] (#58) Implement requirement rule CPMR0074 This introduces the latest requirement rule that was added in Package Validator related to verifying that hook packages has not been used as a dependency. --- ...endency_id=chocolatey_version=2.0.0.verified.txt} | 0 ...ency_id=chocolatey_version=[,2.0.0).verified.txt} | 0 ...d=chocolatey_version=[2.0.0, 3.0.0).verified.txt} | 0 ...ency_id=chocolatey_version=[2.0.0,].verified.txt} | 0 ...pendency_id=chocolatey_version=null.verified.txt} | 0 ...y_id=test-package.hook_version=1.0.0.verified.txt | 8 ++++++++ ...cy_id=test-package.hook_version=null.verified.txt | 8 ++++++++ ...eturnAvailableRulesForImplementation.verified.txt | 6 ++++++ .../Rules/DependenciesElementRulesTests.cs | 12 +++++++++++- .../Rules/DependenciesElementRules.cs | 6 ++++++ 10 files changed, 39 insertions(+), 1 deletion(-) rename src/Chocolatey.Community.Validation.Tests/Rules/{DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=2.0.0.verified.txt => DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=2.0.0.verified.txt} (100%) rename src/Chocolatey.Community.Validation.Tests/Rules/{DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=[,2.0.0).verified.txt => DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=[,2.0.0).verified.txt} (100%) rename src/Chocolatey.Community.Validation.Tests/Rules/{DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=[2.0.0, 3.0.0).verified.txt => DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=[2.0.0, 3.0.0).verified.txt} (100%) rename src/Chocolatey.Community.Validation.Tests/Rules/{DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=[2.0.0,].verified.txt => DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=[2.0.0,].verified.txt} (100%) rename src/Chocolatey.Community.Validation.Tests/Rules/{DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=null.verified.txt => DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=null.verified.txt} (100%) create mode 100644 src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=test-package.hook_version=1.0.0.verified.txt create mode 100644 src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=test-package.hook_version=null.verified.txt diff --git a/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=2.0.0.verified.txt b/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=2.0.0.verified.txt similarity index 100% rename from src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=2.0.0.verified.txt rename to src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=2.0.0.verified.txt diff --git a/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=[,2.0.0).verified.txt b/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=[,2.0.0).verified.txt similarity index 100% rename from src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=[,2.0.0).verified.txt rename to src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=[,2.0.0).verified.txt diff --git a/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=[2.0.0, 3.0.0).verified.txt b/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=[2.0.0, 3.0.0).verified.txt similarity index 100% rename from src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=[2.0.0, 3.0.0).verified.txt rename to src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=[2.0.0, 3.0.0).verified.txt diff --git a/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=[2.0.0,].verified.txt b/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=[2.0.0,].verified.txt similarity index 100% rename from src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=[2.0.0,].verified.txt rename to src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=[2.0.0,].verified.txt diff --git a/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=null.verified.txt b/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=null.verified.txt similarity index 100% rename from src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependencyOnChocolatey_id=chocolatey_version=null.verified.txt rename to src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=chocolatey_version=null.verified.txt diff --git a/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=test-package.hook_version=1.0.0.verified.txt b/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=test-package.hook_version=1.0.0.verified.txt new file mode 100644 index 0000000..229f83c --- /dev/null +++ b/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=test-package.hook_version=1.0.0.verified.txt @@ -0,0 +1,8 @@ +[ + { + HelpUrl: https://ch0.co/rules/cpmr0074, + Id: CPMR0074, + Message: Package has dependency on test-package.hook package. Hook packages should not be defined as a dependency., + Severity: Error + } +] \ No newline at end of file diff --git a/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=test-package.hook_version=null.verified.txt b/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=test-package.hook_version=null.verified.txt new file mode 100644 index 0000000..229f83c --- /dev/null +++ b/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldFlagDependency_id=test-package.hook_version=null.verified.txt @@ -0,0 +1,8 @@ +[ + { + HelpUrl: https://ch0.co/rules/cpmr0074, + Id: CPMR0074, + Message: Package has dependency on test-package.hook package. Hook packages should not be defined as a dependency., + Severity: Error + } +] \ No newline at end of file diff --git a/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldReturnAvailableRulesForImplementation.verified.txt b/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldReturnAvailableRulesForImplementation.verified.txt index 840e81a..1ba2050 100644 --- a/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldReturnAvailableRulesForImplementation.verified.txt +++ b/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.ShouldReturnAvailableRulesForImplementation.verified.txt @@ -10,5 +10,11 @@ Id: CPMR0062, Summary: A dependency on Chocolatey CLI has been added., HelpUrl: https://ch0.co/rules/cpmr0062 + }, + { + Severity: Error, + Id: CPMR0074, + Summary: Package has dependency on .hook package., + HelpUrl: https://ch0.co/rules/cpmr0074 } ] \ No newline at end of file diff --git a/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.cs b/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.cs index 8291ff0..38e6b43 100644 --- a/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.cs +++ b/src/Chocolatey.Community.Validation.Tests/Rules/DependenciesElementRulesTests.cs @@ -13,7 +13,9 @@ public class DependenciesElementRulesTests : RuleTestBase Validate(global::NuGet.Packaging.NuspecReader reader) { @@ -38,6 +39,10 @@ public override IEnumerable Validate(global::NuGet.Packaging.NuspecR yield return GetRule(ChocolateyDependencyRuleId, message); } + else if (dependency.Id.EndsWith(".hook", StringComparison.OrdinalIgnoreCase)) + { + yield return GetRule(HookDependencyRuleId, $"Package has dependency on {dependency.Id} package. Hook packages should not be defined as a dependency."); + } } } @@ -45,6 +50,7 @@ public override IEnumerable Validate(global::NuGet.Packaging.NuspecR { yield return (RuleType.Error, DeprecatedNoDependencyRuleId, "Deprecated packages must have a dependency."); yield return (RuleType.Note, ChocolateyDependencyRuleId, "A dependency on Chocolatey CLI has been added."); + yield return (RuleType.Error, HookDependencyRuleId, "Package has dependency on .hook package."); } } }