Skip to content

Commit 7204a62

Browse files
committed
Fix comment-based help formatting and enhance QA tests for example code blocks
1 parent b9a3a66 commit 7204a62

5 files changed

Lines changed: 59 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
184184

185185
### Fixed
186186

187+
- `New-SqlDscFileGroup`
188+
- Fixed comment-based help example formatting by moving inline comment
189+
to the description text.
190+
- QA Tests
191+
- Added new test to detect comments within multi-line example code blocks
192+
in comment-based help. Comments in the code portion of `.EXAMPLE` blocks
193+
cause PlatyPS documentation generation to fail with "Expect Heading" errors.
187194
- Unit Tests
188195
- Fixed PowerShell class type identity issues that caused "Cannot convert
189196
'Type' to 'Type'" errors when running multiple test files in the same

source/Public/New-SqlDscFileGroup.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@
5656
5757
.EXAMPLE
5858
$fileGroup = New-SqlDscFileGroup -Name 'MyFileGroup'
59-
# Later add to database
6059
Add-SqlDscFileGroup -Database $database -FileGroup $fileGroup
6160
62-
Creates a standalone FileGroup that can be added to a Database later.
61+
Creates a standalone FileGroup that can be added to a Database later
62+
using Add-SqlDscFileGroup.
6363
6464
.EXAMPLE
6565
$fileGroupSpec = New-SqlDscFileGroup -Name 'PRIMARY' -AsSpec

source/Public/Request-SqlDscRSDatabaseRightsScript.ps1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,8 @@
4343
database for the Reporting Services service account.
4444
4545
.EXAMPLE
46-
# Get the Reporting Services service account name
4746
$rsService = Get-SqlDscManagedComputerService -ServiceType 'ReportingServices'
4847
$serviceAccount = $rsService.ServiceAccount
49-
50-
# Generate and execute the rights script
5148
$config = Get-SqlDscRSConfiguration -InstanceName 'SSRS'
5249
$script = $config | Request-SqlDscRSDatabaseRightsScript -DatabaseName 'ReportServer' -UserName $serviceAccount
5350
Invoke-SqlDscQuery -ServerName 'localhost' -InstanceName 'RSDB' -DatabaseName 'master' -Query $script -Force

source/Public/Request-SqlDscRSDatabaseScript.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
3737
.EXAMPLE
3838
$config = Get-SqlDscRSConfiguration -InstanceName 'SSRS'
39-
$script = Request-SqlDscRSDatabaseScript -Configuration $config -DatabaseName 'ReportServer'
39+
$script = $config | Request-SqlDscRSDatabaseScript -DatabaseName 'ReportServer'
4040
Invoke-SqlDscQuery -ServerName 'localhost' -InstanceName 'RSDB' -DatabaseName 'master' -Query $script -Force
4141
4242
Generates the database creation script and executes it on the RSDB

tests/QA/module.tests.ps1

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,55 @@ Describe 'Comment-based help structure' -Tags 'helpQuality' {
238238
$invalidDirectives | Should -BeNullOrEmpty -Because ('invalid help directives found that will break help parsing: {0}' -f ($invalidDirectives -join ', '))
239239
}
240240
}
241+
242+
It 'Should not have comments within multi-line example code blocks for <Name>' {
243+
<#
244+
PlatyPS expects .EXAMPLE blocks to have: code (no comments) → blank line → description.
245+
Comments (lines starting with #) within the code portion cause "Expect Heading" errors
246+
during documentation generation because PlatyPS interprets them incorrectly.
247+
#>
248+
if ($scriptFileRawContent -match '(?s)<#(.*?)#>')
249+
{
250+
$helpBlock = $Matches[1]
251+
252+
# Find all .EXAMPLE blocks
253+
$exampleMatches = [regex]::Matches($helpBlock, '(?s)\.EXAMPLE\s*\r?\n(.*?)(?=\r?\n\s*\.(?:EXAMPLE|PARAMETER|SYNOPSIS|DESCRIPTION|INPUTS|OUTPUTS|NOTES|LINK|COMPONENT|ROLE|FUNCTIONALITY)|$)')
254+
255+
$examplesWithComments = @()
256+
257+
foreach ($exampleMatch in $exampleMatches)
258+
{
259+
$exampleContent = $exampleMatch.Groups[1].Value
260+
$exampleLines = $exampleContent -split '\r?\n'
261+
262+
# Find where the description starts (first line after a blank line that follows code)
263+
$inCodeBlock = $true
264+
$foundBlankLine = $false
265+
266+
foreach ($line in $exampleLines)
267+
{
268+
$trimmedLine = $line.Trim()
269+
270+
if ($inCodeBlock)
271+
{
272+
if ([string]::IsNullOrEmpty($trimmedLine))
273+
{
274+
# Blank line - marks end of code block
275+
$foundBlankLine = $true
276+
$inCodeBlock = $false
277+
}
278+
elseif ($trimmedLine -match '^#(?!region|endregion)')
279+
{
280+
# Found a comment in the code block (excluding #region/#endregion)
281+
$examplesWithComments += $trimmedLine
282+
}
283+
}
284+
}
285+
}
286+
287+
$examplesWithComments | Should -BeNullOrEmpty -Because ('comments within example code blocks break PlatyPS documentation generation: {0}' -f ($examplesWithComments -join ', '))
288+
}
289+
}
241290
}
242291
}
243292

0 commit comments

Comments
 (0)