Skip to content

Commit

Permalink
Merge pull request #170 from AdmiringWorm/feature/tags-not-empty
Browse files Browse the repository at this point in the history
(GH-70) Implemented validation for tags being supplied
  • Loading branch information
gep13 committed Mar 9, 2019
2 parents f844eef + f6762b0 commit 105f5cc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/input/docs/rules/choco0013.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
Title: Tags Are Missing
Description:
Category: Requirements
---

:::{.alert .alert-warning}
**Preliminary Notice**
This rule is not yet available in chocolatey-vscode.
It is a planned rule for 0.8.0.
:::

## Issue

In the nuspec, there is a `<tags />` element. It was found to be missing or empty in the package.

## Recommended Solution

Please update the nuspec to include a `<tags />` element that is non-empty. If your nuspec file is missing this field, you should run the `Chocolatey: Create new Chocolatey package` with the default template and look at the output from that (ensure you have the [latest version of Chocolatey](https://chocolatey.org/packages?q=id%3Achocolatey)).

## Reasoning

Tags aid in categorization of packages and underlying software. Tags should be relevant to the software that is being installed. It will give folks more options when searching for particular software on the site and may turn up in results it may have not otherwise came up in.

## See also

- [Package validator rule](https://github.com/chocolatey/package-validator/wiki/TagsNotEmpty){target = _blank}
33 changes: 33 additions & 0 deletions src/Chocolatey.Language.Server/Validations/TagsNotEmpty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chocolatey.Language.Server.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;

namespace Chocolatey.Language.Server.Validations
{
/// <summary>
/// Handler to validate that no tags contain a comma.
/// </summary>
/// <seealso href="https://github.com/chocolatey/package-validator/blob/master/src/chocolatey.package.validator/infrastructure.app/rules/TagsAreSpaceSeparatedRequirement.cs">Package validator comma separated tags validation rule.</seealso>
public sealed class TagsNotEmpty : NuspecRuleBase
{
private const string VALIDATION_MESSAGE = "Tags (tags) are space separated values for referencing categories for software. " +
"Please include tags in the nuspec as space separated values";

public override string Id => "choco0013";

public override string DocumentationUrl => $"https://gep13.github.io/chocolatey-vscode/docs/rules/{Id}";

public override ValidationType ValidationType => ValidationType.Requirement;

public override IEnumerable<Diagnostic> Validate(Package package)
{
if (!package.Tags.Any() || package.Tags.All(t => string.IsNullOrWhiteSpace(t)))
{
yield return CreateDiagnostic(package, VALIDATION_MESSAGE);
}
}
}
}

0 comments on commit 105f5cc

Please sign in to comment.