Skip to content

Commit

Permalink
(chocolatey-community#36) Implement note rule CPMR0067
Browse files Browse the repository at this point in the history
This implements a new note rule for CPMR0067 that checks if the tag
`notSilent` has been used or not.
  • Loading branch information
AdmiringWorm committed Nov 28, 2024
1 parent e1e65f7 commit b069215
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
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.");
}
}
}

0 comments on commit b069215

Please sign in to comment.