Skip to content

Commit d11d56c

Browse files
authored
Merge pull request #176 from mkevenaar/feature/GH-70/AuthorDoesNotMatchMaintainerNote
(GH-70) Validates that the author does not match the maintainer
2 parents e1d148b + 848af9b commit d11d56c

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

docs/input/docs/rules/choco3002.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
Title: AuthorDoesNotMatchMaintainer
3+
Order: 20
4+
Description:
5+
Category: Notes
6+
---
7+
8+
:::{.alert .alert-warning}
9+
**Preliminary Notice**
10+
This rule is not yet available in chocolatey-vscode.
11+
It is a planned rule for 0.8.0.
12+
:::
13+
14+
**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)
15+
16+
## Issue
17+
18+
In the nuspec,
19+
20+
## Recommended Solution
21+
22+
Please update _ so that _
23+
24+
## Reasoning
25+
26+
## See also
27+
28+
- [Package validator rule](https://github.com/chocolatey/package-validator/wiki/AuthorDoesNotMatchMaintainer){target = _blank}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Text.RegularExpressions;
4+
using Chocolatey.Language.Server.Models;
5+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
6+
using DiagnosticSeverity = OmniSharp.Extensions.LanguageServer.Protocol.Models.DiagnosticSeverity;
7+
8+
namespace Chocolatey.Language.Server.Validations
9+
{
10+
/// <summary>
11+
/// Runs validation of the current nuspec to verify that the author and owner
12+
/// do not match.
13+
/// </summary>
14+
/// <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>
15+
public sealed class AuthorDoesNotMatchMaintainer : NuspecRuleBase
16+
{
17+
/// <inheritdoc />
18+
/// <summary>
19+
/// Gets the string Id for the rule, similar to CHOCO0001
20+
/// </summary>
21+
public override string Id => "choco3002";
22+
23+
/// <inheritdoc />
24+
/// <summary>
25+
/// Gets the type of of validation
26+
/// </summary>
27+
public override ValidationType ValidationType => ValidationType.Note;
28+
29+
public override IEnumerable<Diagnostic> Validate(Package package)
30+
{
31+
var owners = string.Join(",", package.Maintainers).ToLower();
32+
var authors = string.Join(",", package.Authors).ToLower();
33+
if (package.Maintainers.Count <= 0)
34+
{
35+
yield break;
36+
}
37+
38+
if (owners.Equals(authors))
39+
{
40+
yield return CreateDiagnostic(
41+
package.Maintainers.First().TextStart,
42+
package.Maintainers.Last().TextEnd,
43+
"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."
44+
);
45+
yield return CreateDiagnostic(
46+
package.Authors.First().TextStart,
47+
package.Authors.Last().TextEnd,
48+
"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."
49+
);
50+
}
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)