Skip to content

Invoke-Formatter is not idempotent on --% verbatim arguments #2209

Description

@kjanat

Steps to reproduce

Run the formatter repeatedly on a native command that uses the stop-parsing token:

$formatted = $null
1..3 | ForEach-Object {
    $formatted = Invoke-Formatter ($formatted ?? 'cmd --% raw | text & stuff')
    $formatted
}

Expected behavior

Formatting already formatted output should be a no-op. Spacing adjacent to the verbatim argument should either be left untouched or normalized once to a stable result.

Actual behavior

One additional space is inserted before | on every run:

cmd --% raw  | text & stuff
cmd --% raw   | text & stuff
cmd --% raw    | text & stuff

The output grows without bound in a format-on-save loop.

The verbatim-argument token owns the text up to the pipe. PSUseConsistentWhitespace with CheckPipe sees a zero-width gap before | and inserts a space inside the verbatim argument's extent on each formatting pass.

Environment data

Reproduced with:

  • PSScriptAnalyzer 1.25.0 on PowerShell 7.5.2
  • PSScriptAnalyzer 1.25.0 on PowerShell 7.6.3
  • 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