From e6586b01598a257d530da7f29b1ccaa73ad66f9a Mon Sep 17 00:00:00 2001 From: AdmiringWorm Date: Thu, 28 Nov 2024 11:40:01 +0100 Subject: [PATCH] (#36) Implement note rule CPMR0067 This implements a new note rule for CPMR0067 that checks if the tag `notSilent` has been used or not. --- ...gCommaSeparatedTags_tags=NOTSILENT.verified.txt | 8 ++++++++ ...urnAvailableRulesForImplementation.verified.txt | 6 ++++++ .../Rules/TagsElementRulesTests.cs | 14 ++++++++++---- .../Rules/TagsElementRules.cs | 7 +++++++ 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 src/Chocolatey.Community.Validation.Tests/Rules/TagsElementRulesTests.ShouldFlagCommaSeparatedTags_tags=NOTSILENT.verified.txt diff --git a/src/Chocolatey.Community.Validation.Tests/Rules/TagsElementRulesTests.ShouldFlagCommaSeparatedTags_tags=NOTSILENT.verified.txt b/src/Chocolatey.Community.Validation.Tests/Rules/TagsElementRulesTests.ShouldFlagCommaSeparatedTags_tags=NOTSILENT.verified.txt new file mode 100644 index 0000000..b0fb776 --- /dev/null +++ b/src/Chocolatey.Community.Validation.Tests/Rules/TagsElementRulesTests.ShouldFlagCommaSeparatedTags_tags=NOTSILENT.verified.txt @@ -0,0 +1,8 @@ +[ + { + HelpUrl: https://ch0.co/rules/cpmr0067, + Id: CPMR0067, + Message: The tag 'notSilent' is being used., + Severity: Note + } +] \ No newline at end of file diff --git a/src/Chocolatey.Community.Validation.Tests/Rules/TagsElementRulesTests.ShouldReturnAvailableRulesForImplementation.verified.txt b/src/Chocolatey.Community.Validation.Tests/Rules/TagsElementRulesTests.ShouldReturnAvailableRulesForImplementation.verified.txt index d8a221f..44f1bd5 100644 --- a/src/Chocolatey.Community.Validation.Tests/Rules/TagsElementRulesTests.ShouldReturnAvailableRulesForImplementation.verified.txt +++ b/src/Chocolatey.Community.Validation.Tests/Rules/TagsElementRulesTests.ShouldReturnAvailableRulesForImplementation.verified.txt @@ -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 } ] \ No newline at end of file diff --git a/src/Chocolatey.Community.Validation.Tests/Rules/TagsElementRulesTests.cs b/src/Chocolatey.Community.Validation.Tests/Rules/TagsElementRulesTests.cs index e4cc194..a25992d 100644 --- a/src/Chocolatey.Community.Validation.Tests/Rules/TagsElementRulesTests.cs +++ b/src/Chocolatey.Community.Validation.Tests/Rules/TagsElementRulesTests.cs @@ -5,12 +5,14 @@ namespace Chocolatey.Community.Validation.Tests.Rules using Chocolatey.Community.Validation.Rules; using NUnit.Framework; - [Category("Requirements")] public class TagsElementRulesTests : RuleTestBase { - [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); @@ -18,6 +20,7 @@ public async Task ShouldFlagCommaSeparatedTags(string tags) await VerifyNuspec(testContent); } + [Category("Requirements")] [TestCaseSource(nameof(EmptyTestValues))] public async Task ShouldFlagEmptyTags(string tags) { @@ -27,6 +30,7 @@ public async Task ShouldFlagEmptyTags(string tags) } [Test] + [Category("Requirements")] public async Task ShouldFlagMissingTagsElement() { const string testContent = @" @@ -48,6 +52,7 @@ public async Task ShouldFlagMissingTagsElement() } [Test] + [Category("Requirements")] public async Task ShouldNotFlagTagsNotContainingAComma() { var testContent = GetTestContent("awesome-tag with space separated"); @@ -56,6 +61,7 @@ public async Task ShouldNotFlagTagsNotContainingAComma() } [Test] + [Category("Requirements")] public async Task ShouldNotFlagWhenTagsIsNotEmpty() { var testContent = GetTestContent("some awesome tags"); diff --git a/src/Chocolatey.Community.Validation/Rules/TagsElementRules.cs b/src/Chocolatey.Community.Validation/Rules/TagsElementRules.cs index 7c433fe..ef88876 100644 --- a/src/Chocolatey.Community.Validation/Rules/TagsElementRules.cs +++ b/src/Chocolatey.Community.Validation/Rules/TagsElementRules.cs @@ -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 Validate(global::NuGet.Packaging.NuspecReader reader) { @@ -27,12 +28,18 @@ public override IEnumerable 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."); } } }