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

(#36) Add rule for validating usage of notSilent tag #54

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/cpmr0067,
Id: CPMR0067,
Message: The tag 'notSilent' is being used.,
Severity: Note
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@
Id: CPMR0023,
Summary: Packages require at least one tag, and they must be separated by a space.,
HelpUrl: https://ch0.co/rules/cpmr0023
},
{
Severity: Note,
Id: CPMR0067,
Summary: The tag 'notSilent' is being used.,
HelpUrl: https://ch0.co/rules/cpmr0067
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ namespace Chocolatey.Community.Validation.Tests.Rules
using Chocolatey.Community.Validation.Rules;
using NUnit.Framework;

[Category("Requirements")]
public class TagsElementRulesTests : RuleTestBase<TagsElementRules>
{
[TestCase(",taggie")]
[TestCase("taggie,")]
[TestCase("tag1, tag2 tag3")]
[TestCase(",taggie", Category = "Requirements")]
[TestCase("taggie,", Category = "Requirements")]
[TestCase("tag1, tag2 tag3", Category = "Requirements")]
[TestCase("notSilent", Category = "Notes")]
[TestCase("notsilent", Category = "Notes")]
[TestCase("NOTSILENT", Category = "Notes")]
public async Task ShouldFlagCommaSeparatedTags(string tags)
{
var testContent = GetTestContent(tags);

await VerifyNuspec(testContent);
}

[Category("Requirements")]
[TestCaseSource(nameof(EmptyTestValues))]
public async Task ShouldFlagEmptyTags(string tags)
{
Expand All @@ -27,6 +30,7 @@ public async Task ShouldFlagEmptyTags(string tags)
}

[Test]
[Category("Requirements")]
public async Task ShouldFlagMissingTagsElement()
{
const string testContent = @"<?xml version=""1.0"" encoding=""utf-8""?>
Expand All @@ -48,6 +52,7 @@ public async Task ShouldFlagMissingTagsElement()
}

[Test]
[Category("Requirements")]
public async Task ShouldNotFlagTagsNotContainingAComma()
{
var testContent = GetTestContent("awesome-tag with space separated");
Expand All @@ -56,6 +61,7 @@ public async Task ShouldNotFlagTagsNotContainingAComma()
}

[Test]
[Category("Requirements")]
public async Task ShouldNotFlagWhenTagsIsNotEmpty()
{
var testContent = GetTestContent("some awesome tags");
Expand Down
7 changes: 7 additions & 0 deletions src/Chocolatey.Community.Validation/Rules/TagsElementRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public sealed class TagsElementRules : CCRMetadataRuleBase
{
private const string CommaRuleId = "CPMR0014";
private const string EmptyRuleId = "CPMR0023";
private const string NotSilentRuleId = "CPMR0067";

public override IEnumerable<RuleResult> Validate(global::NuGet.Packaging.NuspecReader reader)
{
Expand All @@ -27,12 +28,18 @@ public override IEnumerable<RuleResult> Validate(global::NuGet.Packaging.NuspecR
{
yield return GetRule(CommaRuleId);
}

if (tags.IndexOf("notSilent", StringComparison.OrdinalIgnoreCase) >= 0)
{
yield return GetRule(NotSilentRuleId);
}
}

protected internal override IEnumerable<(RuleType severity, string? id, string summary)> GetRulesInformation()
{
yield return (RuleType.Error, CommaRuleId, "The tags have been separated by a comma; they must be separated by a space.");
yield return (RuleType.Error, EmptyRuleId, "Packages require at least one tag, and they must be separated by a space.");
yield return (RuleType.Note, NotSilentRuleId, "The tag 'notSilent' is being used.");
}
}
}