Skip to content
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

(GH-70) Add validation for use of chocolatey dependency #272

Closed
wants to merge 1 commit into from
Closed
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
28 changes: 28 additions & 0 deletions docs/input/docs/rules/choco3003.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
Title: ChocolateyDependency
Order: 30
Description:
Category: Notes
---

:::{.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/ChocolateyDependency){target = _blank}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Chocolatey.Language.Server.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using DiagnosticSeverity = OmniSharp.Extensions.LanguageServer.Protocol.Models.DiagnosticSeverity;

namespace Chocolatey.Language.Server.Validations
{
/// <summary>
/// Runs validation of the current nuspec to verify the dependency on the
/// chocolatey package ID.
/// </summary>
/// <seealso href="https://github.com/chocolatey/package-validator/blob/master/src/chocolatey.package.validator/infrastructure.app/rules/IncludesChocolateyDependencyNote.cs">Package validator note for taking a dependency on Chocolatey.</seealso>
public sealed class IncludesChocolateyDependencyNote : NuspecRuleBase
{
/// <inheritdoc />
/// <summary>
/// Gets the string Id for the rule, similar to CHOCO0001
/// </summary>
public override string Id => "choco3003";
AdmiringWorm marked this conversation as resolved.
Show resolved Hide resolved

/// <inheritdoc />
/// <summary>
/// Gets the type of of validation
/// </summary>
public override ValidationType ValidationType => ValidationType.Note;

public override IEnumerable<Diagnostic> Validate(Package package)
{
var dependency = package.Dependencies.Any(x =>
string.Equals(x.Value.Id, "chocolatey", StringComparison.OrdinalIgnoreCase));
if (dependency)
{
yield return CreateDiagnostic(
package.Dependencies.First().TextStart,
package.Dependencies.Last().TextEnd,
"The package takes a dependency on Chocolatey. The reviewer will ensure the package uses a specific Chocolatey feature that requires a minimum version."
);
}
}
}
}