Skip to content

Commit

Permalink
Merge pull request #167 from AdmiringWorm/feature/package-id-prerelease
Browse files Browse the repository at this point in the history
(GH-70) Implemented validation rule to check if package id contains pre-release tags
  • Loading branch information
gep13 committed Mar 9, 2019
2 parents e95153b + e9f46ff commit 5a2b4da
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/input/docs/rules/choco0010.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
Title: PrereleaseVersionAsPartOfPackageId
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.
:::

**NOTE**: This page is a stub that has not yet been filled out. If you have questions about this issue, please ask in the review or reach out on [Gitter](https://gitter.im/chocolatey/chocolatey.org)

## Issue

In the nuspec,

## Recommended Solution

Please update _ so that _

## Reasoning

## See also

- [Package validator rule](https://github.com/chocolatey/package-validator/wiki/PrereleaseVersionAsPartOfPackageId){target = _blank}
18 changes: 18 additions & 0 deletions src/Chocolatey.Language.Server/Extensions/MetaValueExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ namespace Chocolatey.Language.Server.Extensions
/// </summary>
public static class MetaValueExtensions
{
public static bool ContainsAny(this MetaValue<string> source, params string[] values)
{
if (source.IsMissing)
{
return false;
}

foreach (var value in values)
{
if (source.Value.Contains(value, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}

return false;
}

public static bool EndsWith(this MetaValue<string> source, string text)
{
return !source.IsMissing && source.Value.EndsWith(text, StringComparison.OrdinalIgnoreCase);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using Chocolatey.Language.Server.Extensions;
using Chocolatey.Language.Server.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;

namespace Chocolatey.Language.Server.Validations
{
/// <summary>
/// Handler to validate the id does not contain a pre-release tag (alpha, beta, prerelease).
/// </summary>
/// <seealso href="https://github.com/chocolatey/package-validator/blob/master/src/chocolatey.package.validator/infrastructure.app/rules/PrereleaseVersionAsPartOfPackageIdRequirement.cs">Package validator rule for package id does not contain pre-release tags.</seealso>
public sealed class PrereleaseVersionAsPartOfPackageId : NuspecRuleBase
{
private const string VALIDATION_MESSAGE = "The package id includes a prerelease version name which should be included only in the version of the package.";

public override string Id => "choco0010";

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.Id.ContainsAny("alpha", "beta", "prerelease"))
{
yield return CreateDiagnostic(package.Id, VALIDATION_MESSAGE);
}
}
}
}

0 comments on commit 5a2b4da

Please sign in to comment.