Skip to content

Preserve Invoke-Formatter idempotence for --% arguments - #2265

Open
Christoph Bergmeister (bergmeister) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-invoke-formatter-idempotency
Open

Christoph Bergmeister (bergmeister) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-invoke-formatter-idempotency

Conversation

Copilot AI commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Repeated formatting of cmd --% raw | text & stuff inserts another space before | on every pass. The parser includes trailing whitespace in the verbatim argument token, causing PSUseConsistentWhitespace to misidentify a missing separator.

  • Boundary handling: Skip pre-pipe spacing corrections immediately after a --% verbatim argument. Continue formatting whitespace after that pipe and around other pipes.
  • Regression coverage: Check repeated formatting with zero, multiple, and tab spacing, plus empty verbatim arguments and redundant-whitespace mode.
# Remains unchanged across formatting passes:
cmd --% raw | text & stuff

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Invoke-Formatter idempotency issue with --% verbatim arguments Preserve Invoke-Formatter idempotence for --% arguments Oct 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 remain for the fix preserving verbatim-argument whitespace before pipes.

No open issues 🎉

What changed in this PR

Addresses #2209 by preventing Invoke-Formatter from repeatedly inserting spaces before pipes following --% verbatim arguments.

Changes:

  • Skip pre-pipe whitespace corrections after verbatim arguments while preserving formatting after the pipe and around other pipes.
  • Add repeated-formatting regression tests for zero, multiple, and tab spacing, plus empty verbatim arguments.
  • Verify redundant-whitespace mode preserves verbatim whitespace while correcting spacing after the pipe.
File Description
Tests/​Rules/​UseConsistentWhitespace.tests.ps1 Tests surrounding pipe formatting and redundant-whitespace handling.
Tests/​Engine/​InvokeFormatter.tests.ps1 Tests verbatim argument preservation across repeated formatting passes.
Rules/​UseConsistentWhitespace.cs Skips pre-pipe spacing corrections immediately after verbatim arguments.

Review effort: Balanced

@bergmeister
Christoph Bergmeister (bergmeister) marked this pull request as ready for review October 28, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants