From 29b8759a1d64dd5f7f3d11b0b949041eb96b8fa3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:30:25 +0000 Subject: [PATCH 1/2] Initial plan From 82b8f3d0402daca65f7a7f88a988dc59348d2ebd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:35:58 +0000 Subject: [PATCH 2/2] Preserve verbatim argument spacing before pipes Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/UseConsistentWhitespace.cs | 6 ++++++ Tests/Engine/InvokeFormatter.tests.ps1 | 16 ++++++++++++++++ Tests/Rules/UseConsistentWhitespace.tests.ps1 | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/Rules/UseConsistentWhitespace.cs b/Rules/UseConsistentWhitespace.cs index 7f7550ffe..f96f68b13 100644 --- a/Rules/UseConsistentWhitespace.cs +++ b/Rules/UseConsistentWhitespace.cs @@ -362,6 +362,12 @@ private IEnumerable FindPipeViolations(TokenOperations tokenOp continue; } + // The verbatim argument after --% owns any trailing whitespace before the pipe. + if (pipe.Previous.Previous?.Value.Text == "--%") + { + continue; + } + if (!IsPreviousTokenApartByWhitespace(pipe, out bool hasRedundantWhitespace)) { if (CheckPipeForRedundantWhitespace && hasRedundantWhitespace || CheckPipe && !hasRedundantWhitespace) diff --git a/Tests/Engine/InvokeFormatter.tests.ps1 b/Tests/Engine/InvokeFormatter.tests.ps1 index dcc0a6174..1705a7705 100644 --- a/Tests/Engine/InvokeFormatter.tests.ps1 +++ b/Tests/Engine/InvokeFormatter.tests.ps1 @@ -84,6 +84,22 @@ function foo { } Context "When no settings are given" { + It "Should preserve verbatim arguments across repeated formatting passes: " -TestCases @( + @{ ScriptDefinition = 'cmd --% raw | text & stuff' } + @{ ScriptDefinition = 'cmd --% raw| text' } + @{ ScriptDefinition = 'cmd --% raw | text' } + @{ ScriptDefinition = "cmd --% raw`t| text" } + @{ ScriptDefinition = 'cmd --% | text' } + ) { + param($ScriptDefinition) + + $formatted = $ScriptDefinition + 1..3 | ForEach-Object { + $formatted = Invoke-Formatter $formatted + $formatted | Should -BeExactly $ScriptDefinition + } + } + It "Should format using default settings" { $def = @' function foo diff --git a/Tests/Rules/UseConsistentWhitespace.tests.ps1 b/Tests/Rules/UseConsistentWhitespace.tests.ps1 index c2013fa31..c7c9c5be9 100644 --- a/Tests/Rules/UseConsistentWhitespace.tests.ps1 +++ b/Tests/Rules/UseConsistentWhitespace.tests.ps1 @@ -358,6 +358,19 @@ $x = "abc"; Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -Be $null } + It "Should still correct whitespace after a pipe following a verbatim argument" { + $def = 'cmd --% raw |text' + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings + @($violations).Count | Should -Be 1 + Test-CorrectionExtentFromContent $def $violations 1 '' ' ' + Invoke-Formatter $def -Settings $settings | Should -BeExactly 'cmd --% raw | text' + } + + It "Should still format other pipes around a command with verbatim arguments" { + $def = 'foo|cmd --% raw |text|more' + Invoke-Formatter $def -Settings $settings | Should -BeExactly 'foo | cmd --% raw | text | more' + } + It "Should not find a violation if a backtick is before the pipe" { $def = @' Get-Item ` @@ -404,6 +417,11 @@ foo $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings | Should -BeNullOrEmpty } + It "Should preserve whitespace in verbatim arguments while removing redundant whitespace after the pipe" { + $def = 'cmd --% raw | text' + Invoke-Formatter $def -Settings $settings | Should -BeExactly 'cmd --% raw | text' + } + It "Should find a violation if there is one space too much before pipe" { $def = 'foo | bar' $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings