Skip to content

Commit 2ae5a3d

Browse files
authored
Merge pull request #164 from AdmiringWorm/feature/deprecated-pkg-rule
(GH-70) Implemented rule to validate deprecated package have dependency
2 parents 56bb8ba + 37bdc9b commit 2ae5a3d

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

docs/input/docs/rules/choco0007.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
Title: DeprecatedPackagesMustHaveADependency
3+
Description:
4+
Category: Requirements
5+
---
6+
7+
:::{.alert .alert-warning}
8+
**Preliminary Notice**
9+
This rule is not yet available in chocolatey-vscode.
10+
It is a planned rule for 0.8.0.
11+
:::
12+
13+
**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)
14+
15+
## Issue
16+
17+
In the nuspec,
18+
19+
## Recommended Solution
20+
21+
Please update _ so that _
22+
23+
## Reasoning
24+
25+
## See also
26+
27+
- [Package validator rule](https://github.com/chocolatey/package-validator/wiki/DeprecatedPackagesMustHaveADependency){target = _blank}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Chocolatey.Language.Server.Models;
5+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
6+
7+
namespace Chocolatey.Language.Server.Validations
8+
{
9+
public sealed class DeprecatedPackagesShouldHaveDependency : NuspecRuleBase
10+
{
11+
private const string VALIDATION_MESSAGE = "Deprecated Packages must contain a dependency to the package(s) which the package is deprecating for.";
12+
public override string Id => "choco0007";
13+
14+
public override string DocumentationUrl => $"https://gep13.github.io/chocolatey-vscode/docs/rules/{Id}";
15+
16+
public override ValidationType ValidationType => ValidationType.Requirement;
17+
18+
public override IEnumerable<Diagnostic> Validate(Package package)
19+
{
20+
if (package.Title.IsMissing)
21+
{
22+
yield break;
23+
}
24+
25+
if (package.Title.Value.Contains("deprecated", StringComparison.OrdinalIgnoreCase)
26+
&& !package.Dependencies.Any())
27+
{
28+
yield return CreateDiagnostic(package, VALIDATION_MESSAGE);
29+
}
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)