From 944a44d756151b9a913d24b3acb4cd6b2250277f Mon Sep 17 00:00:00 2001 From: bergmeister <9250262+bergmeister@users.noreply.github.com> Date: Tue, 27 Oct 2026 18:29:59 +0000 Subject: [PATCH] test: cover comment indentation in pipelines Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Rules/UseConsistentIndentation.tests.ps1 | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index 81c90d324..f1ce8839e 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -902,6 +902,37 @@ bar Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should -Be $def } + It "Should preserve comment-run indentation in a multiline pipeline using " -TestCases @( + @{ + PipelineIndentation = 'IncreaseIndentationForFirstPipeline' + ExpectedFinalCommandIndentation = ' ' + } + @{ + PipelineIndentation = 'IncreaseIndentationAfterEveryPipeline' + ExpectedFinalCommandIndentation = ' ' + } + ) { + param( + [string] $PipelineIndentation, + [string] $ExpectedFinalCommandIndentation + ) + $def = @( + 'foo |' + ' # first comment' + ' # nested comment' + ' bar |' + "${ExpectedFinalCommandIndentation}baz" + ) -join "`n" + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = $PipelineIndentation + + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings + $violations | Should -BeNullOrEmpty + $formatted = Invoke-Formatter -ScriptDefinition $def -Settings $settings + $formatted | Should -Be $def + Invoke-Formatter -ScriptDefinition $formatted -Settings $settings | + Should -Be $def + } + It "Should preserve pipeline indentation across a comment line continuation with PipelineIndentation None" { $def = @' foo |