Skip to content

Commit 2c3d26d

Browse files
Fix PSScriptAnalyzer violations: add comment help and OutputType declarations
- Add [PSProvideCommentHelp] comment blocks to 8 private helper functions: ConvertFrom-YamlMapping, ConvertFrom-YamlSequence, Test-YamlMappingType, Test-YamlSequenceType, ConvertTo-YamlMapping, ConvertTo-YamlSequence, Format-YamlDoubleQuoted, Format-YamlKey - Add [OutputType] to ConvertFrom-YamlMapping, ConvertFrom-YamlSequence, ConvertFrom-YamlScalar - Suppress PSUseOutputTypeCorrectly on 4 functions that use comma-unary operator to prevent collection unwrapping (ConvertFrom-YamlLineStream, ConvertFrom-YamlSequence, Get-YamlMappingPair, ConvertFrom-Yaml)
1 parent 84344f7 commit 2c3d26d

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/functions/private/ConvertFrom-YamlLineStream.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
- Inline comments (` #...` outside quotes) are stripped from the content.
1111
- Tabs in indentation are not allowed (YAML spec); they are treated as one space here.
1212
#>
13+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseOutputTypeCorrectly', '',
14+
Justification = 'Comma-unary operator preserves List type; PSScriptAnalyzer misdetects as Object[].')]
1315
[CmdletBinding()]
1416
[OutputType([System.Collections.Generic.List[pscustomobject]])]
1517
param(

src/functions/private/ConvertFrom-YamlNode.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@
4040
}
4141

4242
function ConvertFrom-YamlMapping {
43+
<#
44+
.SYNOPSIS
45+
Parses a YAML block-style mapping into a PSCustomObject or OrderedDictionary.
46+
#>
4347
[CmdletBinding()]
48+
[OutputType([System.Collections.Specialized.OrderedDictionary], [pscustomobject])]
4449
param(
4550
[Parameter(Mandatory)] [pscustomobject] $Context,
4651
[Parameter(Mandatory)] [int] $Indent,
@@ -107,7 +112,14 @@ function ConvertFrom-YamlMapping {
107112
}
108113

109114
function ConvertFrom-YamlSequence {
115+
<#
116+
.SYNOPSIS
117+
Parses a YAML block-style sequence into a PowerShell array.
118+
#>
119+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseOutputTypeCorrectly', '',
120+
Justification = 'Comma-unary operator preserves array type; PSScriptAnalyzer misdetects as Object[].')]
110121
[CmdletBinding()]
122+
[OutputType([object[]])]
111123
param(
112124
[Parameter(Mandatory)] [pscustomobject] $Context,
113125
[Parameter(Mandatory)] [int] $Indent,
@@ -212,6 +224,7 @@ function ConvertFrom-YamlScalar {
212224
Converts a raw YAML scalar token into the appropriate PowerShell type.
213225
#>
214226
[CmdletBinding()]
227+
[OutputType([string], [bool], [int], [long], [double])]
215228
param(
216229
[Parameter(Mandatory)]
217230
[AllowEmptyString()]

src/functions/private/ConvertTo-YamlNode.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
}
5757

5858
function Test-YamlMappingType {
59+
<#
60+
.SYNOPSIS
61+
Returns true when a value should be serialized as a YAML mapping.
62+
#>
5963
[CmdletBinding()]
6064
[OutputType([bool])]
6165
param([Parameter()] [AllowNull()] [object] $Value)
@@ -70,6 +74,10 @@ function Test-YamlMappingType {
7074
}
7175

7276
function Test-YamlSequenceType {
77+
<#
78+
.SYNOPSIS
79+
Returns true when a value should be serialized as a YAML sequence.
80+
#>
7381
[CmdletBinding()]
7482
[OutputType([bool])]
7583
param([Parameter()] [AllowNull()] [object] $Value)
@@ -82,6 +90,10 @@ function Test-YamlSequenceType {
8290
}
8391

8492
function ConvertTo-YamlMapping {
93+
<#
94+
.SYNOPSIS
95+
Writes a mapping value as a YAML block-style mapping into the StringBuilder.
96+
#>
8597
[CmdletBinding()]
8698
param(
8799
[Parameter(Mandatory)] [object] $Value,
@@ -142,6 +154,10 @@ function ConvertTo-YamlMapping {
142154
}
143155

144156
function ConvertTo-YamlSequence {
157+
<#
158+
.SYNOPSIS
159+
Writes a sequence value as a YAML block-style sequence into the StringBuilder.
160+
#>
145161
[CmdletBinding()]
146162
param(
147163
[Parameter(Mandatory)] [object] $Value,
@@ -230,6 +246,8 @@ function Get-YamlMappingPair {
230246
.SYNOPSIS
231247
Returns a list of [pscustomobject]@{ Key; Value } for a dictionary or PSObject.
232248
#>
249+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseOutputTypeCorrectly', '',
250+
Justification = 'Comma-unary operator preserves List type; PSScriptAnalyzer misdetects as Object[].')]
233251
[CmdletBinding()]
234252
[OutputType([System.Collections.Generic.List[pscustomobject]])]
235253
param(
@@ -343,6 +361,10 @@ function Format-YamlString {
343361
}
344362

345363
function Format-YamlDoubleQuoted {
364+
<#
365+
.SYNOPSIS
366+
Wraps a string in double quotes, escaping special characters per YAML rules.
367+
#>
346368
[CmdletBinding()]
347369
[OutputType([string])]
348370
param(
@@ -371,6 +393,10 @@ function Format-YamlDoubleQuoted {
371393
}
372394

373395
function Format-YamlKey {
396+
<#
397+
.SYNOPSIS
398+
Renders a mapping key as a YAML scalar, quoting when necessary.
399+
#>
374400
[CmdletBinding()]
375401
[OutputType([string])]
376402
param(

src/functions/public/ConvertFrom-Yaml.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
System.Collections.Specialized.OrderedDictionary
5252
#>
5353
[Alias('ConvertFrom-Yml')]
54+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseOutputTypeCorrectly', '',
55+
Justification = 'Comma-unary operator for -NoEnumerate returns array wrapper; PSScriptAnalyzer misdetects as Object[].')]
5456
[CmdletBinding()]
5557
[OutputType([PSCustomObject], [System.Collections.Specialized.OrderedDictionary])]
5658
param(

0 commit comments

Comments
 (0)