Skip to content

Invoke-Formatter -Range silently drops corrections after earlier fixes shift text #2211

Description

@kjanat

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 main at 4b0117c on PowerShell 7.6.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions