Skip to content

(GH-70) Implemented validation for tags being supplied #170

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

Merged
merged 3 commits into from
Mar 9, 2019
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
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);
}
}
}
}