PowerShell / PowerShell/PSScriptAnalyzer
`Invoke-Formatter -Range` silently drops corrections after earlier fixes shift text
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
Description
Steps to reproduce
Format only the second line, with the range covering the complete statement:
Invoke-Formatter -ScriptDefinition "if(`$a){'x'}`nif(`$b){'y'}" -Range @(2, 1, 2, 12)
Expected behavior
Every formatting correction within the selected statement should be applied:
if($a){'x'}
if ($b) { 'y' }
Actual behavior
The space before the final } is missing:
if($a){'x'}
if ($b) { 'y'}
The formatter applies fixes iteratively. Earlier corrections make the selected line longer, but later violations are still filtered against the original fixed range coordinates. Once a correction shifts beyond the original range end, it is silently dropped even though it belongs to the statement selected by the caller.
Expected resolution
Track the range through applied edits, or filter corrections once against their original extents, so that a range covering a complete statement formats that statement completely.
Environment data
Reproduced with:
- PSScriptAnalyzer 1.25.0 on PowerShell 7.5.2
- PSScriptAnalyzer built from
mainat PowerShell/PSScriptAnalyzer@4b0117ca7d2887711c9699f467ba7171f8859156 on PowerShell 7.6.4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Invoke-Formatter -Range entry point and reproduce the supplied command on the stated PSScriptAnalyzer versions. Trace how iterative formatting corrections are filtered against the selected range, then verify that every correction within the complete statement is applied, including the final space before }.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100