GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix PlaceOpenBrace/PlaceCloseBrace corrections leaving stray whitespace and misindented braces by Copilot · Pull Request #2262 · PowerShell/PSScriptAnalyzer

Conversation

Copilot AI commented Oct 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

With IgnoreOneLineBlock = $false, splitting a one-line if/else produced stray leading and trailing spaces, a } indented by 3 spaces, and a else with a leading space:

Invoke-Formatter -ScriptDefinition "if (`$RegEx) { '-match' } else { '-like' }" -Settings @{
    Rules = @{
        PSPlaceOpenBrace  = @{ Enable = $true; IgnoreOneLineBlock = $false }
        PSPlaceCloseBrace = @{ Enable = $true; IgnoreOneLineBlock = $false }
    }
}
Before After
if ($RegEx) {
'-match'
}
else {
'-like'
}
if ($RegEx) {
'-match'
}
else {
'-like'
}

About the issue's expected output: these settings run only the two brace rules. PSPlaceCloseBrace.NewLineAfter defaults to $true, so it puts else on its own line, and none of the enabled rules indents the body (that's PSUseConsistentIndentation). The "After" column is therefore the correct result. The CodeFormattingOTBS preset with IgnoreOneLineBlock = $false now produces exactly the output the issue expected:

if ($RegEx) {
    '-match'
} else {
    '-like'
}

Changes

  • PlaceOpenBrace, NewLineAfter correction: the correction extent now runs from { to the next token on the same line, so it also removes the whitespace after the brace.
  • PlaceCloseBrace, BraceShouldBeOnNewLine correction: when the preceding token is on the same line, the extent now starts at that token's end, so it also removes the whitespace before }.
  • PlaceCloseBrace.GetIndentation: the loop condition was k > 0, so it never checked the first token in the script. When the open brace was on the first line, } took its indentation from the 2nd token (( → 3 spaces). Changed to k >= 0. This also affects the NoEmptyLineBefore correction, which uses the same helper.
  • PlaceCloseBrace, NewLineAfter correction: the extent now runs from } up to the branch keyword (else/elseif/catch/finally). The replacement is } + newline + the brace's indentation, so the keyword lines up with } and no leading space remains.

Tests

  • Three existing correction-extent tests now expect ViolationText to be '} ' (brace plus the following space) because the extent now includes that space.
  • Added regression tests:
    • the scenario from the issue;
    • a nested block, to check that } and else keep their indentation;
    • the OTBS preset with IgnoreOneLineBlock = $false;
    • the open-brace correction extent.
  • Fixes IgnoreOneLineBlock=$false Correction Issue in PSPlaceOpenBrace and PSPlaceCloseBrace #2218

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Initial plan
70c9c34
Copilot AI assigned Copilot and Christoph Bergmeister (bergmeister) Oct 27, 2026
Copilot started work on behalf of Christoph Bergmeister (bergmeister) October 27, 2026 22:28
View session
Copilot AI linked an issue Oct 27, 2026 that may be closed by this pull request
IgnoreOneLineBlock=$false Correction Issue in PSPlaceOpenBrace and PSPlaceCloseBrace #2218
Open
@bergmeister
Fix PlaceOpenBrace/PlaceCloseBrace corrections leaving stray whitespa…
07da3ae
…ce and wrong indentation

Co-authored-by: bergmeister <[email protected]>
Copilot AI changed the title [WIP] Fix IgnoreOneLineBlock=false correction issue in PSPlaceOpenBrace and PSPlaceCloseBrace Fix PlaceOpenBrace/PlaceCloseBrace corrections leaving stray whitespace and misindented braces Oct 27, 2026
Copilot finished work on behalf of Christoph Bergmeister (bergmeister) October 27, 2026 22:37
Copilot AI requested a review from Christoph Bergmeister (bergmeister) October 27, 2026 22:37
@bergmeister
Christoph Bergmeister (bergmeister) requested a balanced review from Copilot October 28, 2026 07:20
Copilot started work on behalf of Christoph Bergmeister (bergmeister) October 28, 2026 07:21
View session
Copilot started reviewing on behalf of Christoph Bergmeister (bergmeister) October 28, 2026 07:21
View session
Copilot AI reviewed Oct 28, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

🟡 Changes recommended

The correction can misalign else after a multiline condition by using the opening-brace line’s indentation instead of preserving the closing brace’s leading whitespace, and regression coverage is needed.

1 open issue
  • Medium severity Derive else indentation from closing brace for multiline conditions · New
What changed in this PR

This PR addresses #2218 by refining brace-formatting corrections so splitting one-line blocks removes stray whitespace and aligns closing braces and branch keywords.

Changes:

  • Extend correction ranges to consume whitespace adjacent to braces.
  • Include the script’s first token when calculating closing-brace indentation.
  • Add regression tests for one-line statements, nested branches, OTBS formatting, and correction ranges.
File Description
Tests/​Rules/​PlaceOpenBrace.tests.ps1 Verify that opening-brace corrections consume following whitespace.
Tests/​Rules/​PlaceCloseBrace.tests.ps1 Update correction expectations and add formatting regressions.
Rules/​PlaceOpenBrace.cs Remove whitespace after { when inserting a newline.
Rules/​PlaceCloseBrace.cs Adjust correction ranges and indentation for closing braces and branches.

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Rules/PlaceCloseBrace.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bergmeister
Make brace formatter expectations platform-independent
17e46ca
Co-authored-by: bergmeister <[email protected]>
Copilot finished work on behalf of Christoph Bergmeister (bergmeister) October 28, 2026 07:26
@bergmeister
Christoph Bergmeister (bergmeister) added this pull request to stack #2272 October 28, 2026 11:40
Copilot AI mentioned this pull request Oct 28, 2026
Preserve branch indentation after multiline conditions #2271
Merged
@bergmeister
Christoph Bergmeister (bergmeister) requested a balanced review from Copilot October 28, 2026 11:43
Copilot started reviewing on behalf of Christoph Bergmeister (bergmeister) October 28, 2026 11:44
View session
Copilot AI reviewed Oct 28, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The formatter uses continuation-line indentation for multiline conditions, causing correctly aligned } else { blocks to gain an extra-indented else that brace-only formatting does not repair.

1 open issue
  • Medium severity Derive else indentation from closing brace for multiline conditions
1 previously missed issue

In code that hasn't changed since last review

Medium severity Use closing brace indentation for split-condition else formatting

Rules/​PlaceCloseBrace.cs:288

For a condition split as if ($a -and followed by an indented $b) {, GetIndentation() returns the continuation line's indentation rather than the closing brace's indentation. An already correctly aligned } else { therefore becomes } followed by an extra-indented else, which brace-only formatting does not repair. Use the closing brace's actual leading whitespace when it already starts its own line, falling back to the helper only for an inline brace.

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bergmeister
Christoph Bergmeister (bergmeister) removed this pull request from stack #2272 October 28, 2026 12:09
@bergmeister
Preserve branch indentation after multiline conditions (#2271)
810f339
* Initial plan

* Preserve close brace indentation for branches

Co-authored-by: bergmeister <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: bergmeister <[email protected]>
@bergmeister
Christoph Bergmeister (bergmeister) requested a balanced review from Copilot October 28, 2026 12:11
Copilot started reviewing on behalf of Christoph Bergmeister (bergmeister) October 28, 2026 12:11
View session
Copilot AI reviewed Oct 28, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

🟡 Changes recommended

The closing-brace rule replaces tab-based indentation with spaces when splitting a branch, misaligning else; it needs to preserve the original leading whitespace and include a tab-indented regression test.

1 open issue
  • Medium severity Preserve tab indentation when formatting closing-brace else branches · New
1 resolved since last review
  • Medium severity Derive else indentation from closing brace for multiline conditions

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Rules/PlaceCloseBrace.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bergmeister
Christoph Bergmeister (bergmeister) added this pull request to stack #2276 October 28, 2026 12:17
Copilot AI mentioned this pull request Oct 28, 2026
Preserve tab indentation when formatting branches #2275
Merged
@bergmeister
Christoph Bergmeister (bergmeister) removed this pull request from stack #2276 October 28, 2026 12:31
@bergmeister
Preserve tab indentation when formatting branches (#2275)
7b3de72
* Initial plan

* Preserve tab indentation when formatting branches

Co-authored-by: bergmeister <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: bergmeister <[email protected]>
@bergmeister
Christoph Bergmeister (bergmeister) requested a balanced review from Copilot October 28, 2026 13:13
Copilot started reviewing on behalf of Christoph Bergmeister (bergmeister) October 28, 2026 13:14
View session
Copilot AI reviewed Oct 28, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the brace-formatting corrections.

No open issues 🎉

1 resolved since last review
  • Medium severity Preserve tab indentation when formatting closing-brace else branches

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bergmeister
Christoph Bergmeister (bergmeister) marked this pull request as ready for review October 28, 2026 13:20
@bergmeister
Christoph Bergmeister (bergmeister) requested a review from a team as a code owner October 28, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@bergmeister Christoph Bergmeister (bergmeister) Awaiting requested review from bergmeister bergmeister is a code owner

At least 1 approving review is required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@bergmeister Christoph Bergmeister (bergmeister)

Copilot code review Copilot

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

IgnoreOneLineBlock=$false Correction Issue in PSPlaceOpenBrace and PSPlaceCloseBrace

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@bergmeister
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.