File tree 3 files changed +71
-2
lines changed
src/Chocolatey.Language.Server/Validations
3 files changed +71
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ Title : Tags Found With Commas
3
+ Description : Tags have been incorrectly separated with commas
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
+ ## Issue
14
+
15
+ In the nuspec in the ` <tags /> ` element, the verifier found that the tags were separated with commas. They should only be separated with spaces.
16
+
17
+ ## Recommended Solution
18
+
19
+ Please remove the commas from the ` <tags /> ` element.
20
+
21
+ ## Reasoning
22
+
23
+ We could just fix this on Chocolatey.org, but tags are used in other places besides just Chocolatey.org, and they are expected to be space separated.
24
+
25
+ ## See also
26
+
27
+ - [ Package validator rule] ( https://github.com/chocolatey/package-validator/wiki/TagsAreSpaceSeparated ) {target = _ blank}
Original file line number Diff line number Diff line change @@ -46,14 +46,17 @@ public abstract class NuspecRuleBase : INuspecRule
46
46
/// <exception cref="ArgumentNullException">
47
47
/// Thrown when <paramref name="metaValue"/> is <c>null</c>.
48
48
/// </exception>
49
- protected Diagnostic CreateDiagnostic ( MetaValue metaValue , string message )
49
+ protected Diagnostic CreateDiagnostic ( MetaValue metaValue , string message , bool useTextIndex = false )
50
50
{
51
51
if ( metaValue == null )
52
52
{
53
53
throw new ArgumentNullException ( nameof ( metaValue ) ) ;
54
54
}
55
55
56
- return CreateDiagnostic ( metaValue . ElementStart , metaValue . ElementEnd , message ) ;
56
+ int start = useTextIndex ? metaValue . TextStart : metaValue . ElementStart ;
57
+ int end = useTextIndex ? metaValue . TextEnd : metaValue . ElementEnd ;
58
+
59
+ return CreateDiagnostic ( start , end , message ) ;
57
60
}
58
61
59
62
/// <summary>
Original file line number Diff line number Diff line change
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
+ /// <summary>
10
+ /// Handler to validate that no tags contain a comma.
11
+ /// </summary>
12
+ /// <seealso href="https://github.com/chocolatey/package-validator/blob/master/src/chocolatey.package.validator/infrastructure.app/rules/TagsAreSpaceSeparatedRequirement.cs">Package validator comma separated tags validation rule.</seealso>
13
+ public sealed class TagsAreSpaceSeparated : NuspecRuleBase
14
+ {
15
+ private const string VALIDATION_MESSAGE = "Tags (tags) are space separated values for referencing categories for software. Please don't use comma to separate tags." ;
16
+
17
+ public override string Id => "choco0012" ;
18
+
19
+ public override string DocumentationUrl => $ "https://gep13.github.io/chocolatey-vscode/docs/rules/{ Id } ";
20
+
21
+ public override ValidationType ValidationType => ValidationType . Requirement ;
22
+
23
+ public override IEnumerable < Diagnostic > Validate ( Package package )
24
+ {
25
+ if ( ! package . Tags . Any ( ) )
26
+ {
27
+ yield break ;
28
+ }
29
+
30
+ foreach ( var tag in package . Tags )
31
+ {
32
+ if ( tag . Value . Contains ( ',' , StringComparison . OrdinalIgnoreCase ) )
33
+ {
34
+ yield return CreateDiagnostic ( tag , VALIDATION_MESSAGE , true ) ;
35
+ }
36
+ }
37
+ }
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments