Skip to content

Commit

Permalink
Merge pull request #59 from AdmiringWorm/issue58
Browse files Browse the repository at this point in the history
(#58) Implement requirement rule CPMR0074
  • Loading branch information
gep13 authored Dec 5, 2024
2 parents 422fa4f + 9ea27a8 commit 51cd93e
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
}
]
Original file line number Diff line number Diff line change
@@ -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
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public class DependenciesElementRulesTests : RuleTestBase<DependenciesElementRul
[TestCase("chocolatey", "[,2.0.0)")]
[TestCase("chocolatey", "[2.0.0, 3.0.0)")]
[TestCase("chocolatey", "[2.0.0,]")]
public async Task ShouldFlagDependencyOnChocolatey(string id, string version)
[TestCase("test-package.hook", null)]
[TestCase("test-package.hook", "1.0.0")]
public async Task ShouldFlagDependency(string id, string version)
{
var testContent = GetTestContent("Test Package", (id, version));

Expand Down Expand Up @@ -67,6 +69,14 @@ public async Task ShouldFlagWhenTitleContainsDeprecatedWithoutDependenciesThatIs
await VerifyNuspec(testContent);
}

[Test]
public async Task ShouldNotFlagDependencyNotUsingCorrectHookExtension()
{
var testContent = GetTestContent("Test Package", ("test-package-hook", null));

await VerifyEmptyResults(testContent);
}

[Test]
public async Task ShouldNotFlagWhenTitleDoesNotContainDeprecatedNotice()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public sealed class DependenciesElementRules : CCRMetadataRuleBase
{
private const string DeprecatedNoDependencyRuleId = "CPMR0017";
private const string ChocolateyDependencyRuleId = "CPMR0062";
private const string HookDependencyRuleId = "CPMR0074";

public override IEnumerable<RuleResult> Validate(global::NuGet.Packaging.NuspecReader reader)
{
Expand All @@ -38,13 +39,18 @@ public override IEnumerable<RuleResult> 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.");
}
}
}

protected internal override IEnumerable<(RuleType severity, string? id, string summary)> GetRulesInformation()
{
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.");
}
}
}

0 comments on commit 51cd93e

Please sign in to comment.