Skip to content

Fix NOTES section formatting in comment-based help#26512

Merged
iSazonov merged 5 commits into
PowerShell:masterfrom
yotsuda:fix-issue-26102
Dec 3, 2025
Merged

Fix NOTES section formatting in comment-based help#26512
iSazonov merged 5 commits into
PowerShell:masterfrom
yotsuda:fix-issue-26102

Conversation

@yotsuda
Copy link
Copy Markdown
Contributor

@yotsuda yotsuda commented Nov 22, 2025

PR Summary

Fixes #26102 - Comment-based help NOTES section had extra blank line and double indentation.

PR Context

The NOTES section in comment-based help had two formatting issues:

  1. Two blank lines after the NOTES header (instead of one)
  2. Content indented 8 spaces (instead of 4, like other sections)

This made the NOTES section visually inconsistent with other help sections like INPUTS, OUTPUTS, etc.

PR Checklist

  • PR has a meaningful title
  • Summarized changes
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge
  • Breaking changes
    • None
  • User-facing changes
    • Not Applicable
  • Testing - New and feature
    • Make sure you've added a new test if existing tests do not effectively test the code changed

Changes

Code Changes

  • Modified Help_format_ps1xml.cs in the control16 definition:
    • Removed extra .AddNewline() call that created the second blank line
    • Removed nested .StartFrame(leftIndent: 4) and .EndFrame() that caused double indentation

Test Changes

  • Added ScriptHelp.NotesFormatting.Tests.ps1 with two Pester tests:
    1. Verifies NOTES header has only one blank line after it (not two)
    2. Verifies NOTES content has 4-space indentation (not 8)

Technical Details

Root Cause:
In Help_format_ps1xml.cs, the control16 definition had:

  1. Two consecutive .AddNewline() calls
  2. Nested StartFrame(leftIndent: 4) causing 4+4=8 space indentation

Before:

NOTES
    
    
        PowerShell includes...  // 8-space indent, 2 blank lines

After:

NOTES
    
    PowerShell includes...  // 4-space indent, 1 blank line

Testing

Manual Testing:

Get-Help Remove-PSSession -Full

Verified NOTES section now matches formatting of other sections.

Pester Tests:
Both tests pass with the fix:

  • Product version: Tests fail (as expected)
  • Fixed version: Tests pass
Tests Passed: 2, Failed: 0

- Remove extra blank line after NOTES header
- Fix double indentation (8 spaces to 4 spaces)
- Add Pester tests to verify the fix

The issue was caused by:
1. Two consecutive .AddNewline() calls creating extra blank line
2. Nested .StartFrame(leftIndent: 4) causing double indentation (4+4=8)

Fixes PowerShell#26102
@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 24, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes formatting issues in the comment-based help NOTES section that caused inconsistent spacing and indentation compared to other help sections. The fix removes an extra newline and eliminates double indentation by removing a nested frame.

Key Changes:

  • Removed duplicate .AddNewline() and nested .StartFrame(leftIndent: 4) in Help_format_ps1xml.cs
  • Added comprehensive Pester tests to verify NOTES section formatting matches other sections

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/System.Management.Automation/FormatAndOutput/DefaultFormatters/Help_format_ps1xml.cs Fixed control16 definition by removing extra newline and nested indentation frame
test/powershell/Language/Scripting/ScriptHelp.NotesFormatting.Tests.ps1 Added tests to verify NOTES section has single blank line and 4-space indentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/powershell/Language/Scripting/ScriptHelp.NotesFormatting.Tests.ps1 Outdated
Comment thread test/powershell/Language/Scripting/ScriptHelp.NotesFormatting.Tests.ps1 Outdated
yotsuda and others added 2 commits November 24, 2025 14:54
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Review - Needed The PR is being reviewed label Dec 1, 2025
@iSazonov
Copy link
Copy Markdown
Collaborator

iSazonov commented Dec 2, 2025

@sdwheeler Could you please look the change? Can we accept it?

@microsoft-github-policy-service microsoft-github-policy-service Bot removed the Review - Needed The PR is being reviewed label Dec 2, 2025
Copy link
Copy Markdown
Collaborator

@sdwheeler sdwheeler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

$lines[$notesIndex + 1] | Should -Match '^\s*$' -Because "There should be a blank line after NOTES header"

# The second line after NOTES header should have content (not another blank line)
# This was the bug: there were TWO blank lines instead of one
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to remove line 25 at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 35b51dc.

$lines[$notesIndex + 2] | Should -Match '\S' -Because "Content should start on the second line after NOTES header (bug was extra blank line)"
}

It 'NOTES content should have 4-space indentation, not 8 (double indentation bug)' {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test duplicates code from previous test. So I suggest to merge these two tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 35b51dc. Merged both tests into one.


# Count leading spaces - should be 4, not 8
# Store capture group immediately to avoid issues with $matches being overwritten
if ($contentLine -match '^(\s+)') {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could simply check that the line start with 4 space string $contentLine.StartsWith(" ").

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StartsWith 4 would match StartsWith 8

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdwheeler is right. I'm using -match '^[ ]{4}\S' instead, which verifies exactly 4 spaces followed by a non-whitespace character. (35b51dc)

@iSazonov iSazonov enabled auto-merge (squash) December 3, 2025 08:11
@iSazonov iSazonov self-assigned this Dec 3, 2025
@iSazonov iSazonov merged commit 5c57c3e into PowerShell:master Dec 3, 2025
36 checks passed
@yotsuda yotsuda deleted the fix-issue-26102 branch December 3, 2025 08:51
SIRMARGIN pushed a commit to SIRMARGIN/PowerShell that referenced this pull request Dec 12, 2025
kilasuit pushed a commit to kilasuit/PowerShell that referenced this pull request Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comment-based help NOTES gets extra blank lines and double indenting

4 participants