GeezerVison is showing github.com — Track formatter ranges through iterative corrections by Copilot · Pull Request #2264 · PowerShell/PSScriptAnalyzer
Conversation
Copilot
AI
commented
Oct 27, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Invoke-Formatter -Range could silently drop later corrections when earlier edits moved them beyond the original range end. Shortening a selected line could also leave invalid range coordinates.
- Range tracking: Update the range end after each applied correction, accounting for both line and column changes across iterations and rules.
- Regression coverage: Cover expansion, contraction, multiline selections, and line insertion/removal while preserving adjacent unselected lines.
Invoke-Formatter -ScriptDefinition "if(`$a){'x'}`nif(`$b){'y'}" -Range @(2, 1, 2, 12)
Produces:
if($a){'x'}
if ($b) { 'y' }
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Copilot
AI
changed the title
[WIP] Fix issue with Invoke-Formatter -Range dropping corrections
Track formatter ranges through iterative corrections
Oct 27, 2026
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
Empty replacements can cause range-endpoint mapping to throw after deleting selected lines, so zero-line replacements need explicit handling, including when no selected lines remain.
1 open issue
What changed in this PR
This PR addresses #2211 by tracking formatter selection boundaries as corrections change the text, so later fixes remain within the intended range.
Changes:
- Update the range endpoint after each correction, accounting for line and column changes.
- Add regression coverage for expanding and shortening selections, inserting and removing lines, and preserving adjacent unselected lines.
| File |
Description |
| Tests/Engine/InvokeFormatter.tests.ps1 |
Adds range-formatting regression cases. |
| Engine/ScriptAnalyzer.cs |
Replaces per-pass line-count adjustment with per-correction endpoint tracking. |
Review effort: Balanced
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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
Zero-line replacements mishandle selection endpoints, potentially causing negative-column exceptions or allowing subsequent formatting to modify originally unselected text.
2 open issues
1 resolved since last review
Review effort: Balanced
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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 block the changes to keep formatter corrections within the intended selection.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
At least 1 approving review is required to merge this pull request.
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
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.
|