Skip to content

Commit

Permalink
Merge pull request #166 from AdmiringWorm/feature/package-id-config
Browse files Browse the repository at this point in the history
(GH-70) Implemented validation rule to check if a package id ends with .config
  • Loading branch information
gep13 committed Mar 9, 2019
2 parents 0695669 + d2b9210 commit e95153b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/input/docs/rules/choco0009.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
Title: PackageIdDoesNotEndWithConfig
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 an automation script (`.ps1`/`.psm1`),

## Recommended Solution

Please update _ so that _

## Reasoning

## See also

- [Package validator rule](https://github.com/chocolatey/package-validator/wiki/PackageIdDoesNotEndWithConfig){target = _blank}
16 changes: 16 additions & 0 deletions src/Chocolatey.Language.Server/Extensions/MetaValueExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using Chocolatey.Language.Server.Models;

namespace Chocolatey.Language.Server.Extensions
{
/// <summary>
/// Helper class to make it easier to test out values in the Meta Value class.
/// </summary>
public static class MetaValueExtensions
{
public static bool EndsWith(this MetaValue<string> source, string text)
{
return !source.IsMissing && source.Value.EndsWith(text, StringComparison.OrdinalIgnoreCase);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
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 end with .config.
/// </summary>
/// <seealso href="https://github.com/chocolatey/package-validator/blob/master/src/chocolatey.package.validator/infrastructure.app/rules/PackageIdDoesNotEndWithConfigRequirement.cs">Package validator rule for package id does not end with .config.</seealso>
public sealed class PackageIdDoesNotEndWithConfig : NuspecRuleBase
{
private const string VALIDATION_MESSAGE = "The package id ends with .config, this is a reserved file extension, and should not be used.";

public override string Id => "choco0009";

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.EndsWith(".config"))
{
yield return CreateDiagnostic(package.Id, VALIDATION_MESSAGE);
}
}
}
}

0 comments on commit e95153b

Please sign in to comment.