|
| 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