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) Validates that the author does not match the maintainer #176

Merged
merged 1 commit into from
Mar 16, 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
28 changes: 28 additions & 0 deletions docs/input/docs/rules/choco3002.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
Title: AuthorDoesNotMatchMaintainer
mkevenaar marked this conversation as resolved.
Show resolved Hide resolved
Order: 20
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/AuthorDoesNotMatchMaintainer){target = _blank}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 that the author and owner
/// do not match.
/// </summary>
/// <seealso href="https://github.com/chocolatey/package-validator/blob/master/src/chocolatey.package.validator/infrastructure.app/rules/AuthorDoesNotMatchMaintainerNote.cs">Package validator note for author and owner values.</seealso>
public sealed class AuthorDoesNotMatchMaintainer : NuspecRuleBase
{
/// <inheritdoc />
/// <summary>
/// Gets the string Id for the rule, similar to CHOCO0001
/// </summary>
public override string Id => "choco3002";

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

public override IEnumerable<Diagnostic> Validate(Package package)
{
var owners = string.Join(",", package.Maintainers).ToLower();
var authors = string.Join(",", package.Authors).ToLower();
if (package.Maintainers.Count <= 0)
{
yield break;
}

if (owners.Equals(authors))
{
yield return CreateDiagnostic(
mkevenaar marked this conversation as resolved.
Show resolved Hide resolved
package.Maintainers.First().TextStart,
package.Maintainers.Last().TextEnd,
"The package maintainer field (owners) matches the software author field (authors) in the nuspec. The reviewer will ensure that the package maintainer is also the software author."
);
yield return CreateDiagnostic(
package.Authors.First().TextStart,
AdmiringWorm marked this conversation as resolved.
Show resolved Hide resolved
package.Authors.Last().TextEnd,
"The package maintainer field (owners) matches the software author field (authors) in the nuspec. The reviewer will ensure that the package maintainer is also the software author."
);
}
}
}
}