Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#58) Implement requirement rule CPMR0074 #59

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.");
}
}
}