From 6f2826ac8949f5ca42b68cdf414175c192381a46 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Oct 2026 22:00:16 +0000 Subject: [PATCH 01/17] Initial plan From 7092b4ce30d1e713675b2788d4e7c357e5bf6ab7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Oct 2026 22:04:29 +0000 Subject: [PATCH 02/17] Preserve comment-run indentation Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/UseConsistentIndentation.cs | 41 ++++++++++-- .../Rules/UseConsistentIndentation.tests.ps1 | 66 +++++++++++++++++++ 2 files changed, 101 insertions(+), 6 deletions(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index 2c77787c6..a5020a04d 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -298,7 +298,10 @@ public override IEnumerable AnalyzeScript(Ast ast, string file } bool lineHasPipelineBeforeToken = LineHasPipelineBeforeToken(tokens, tokenIndex, token); - AddViolation(token, tempIndentationLevel, diagnosticRecords, ref onNewLine, lineHasPipelineBeforeToken); + int commentIndentationOffset = token.Kind == TokenKind.Comment + ? GetCommentRunIndentationOffset(tokens, tokenIndex) + : 0; + AddViolation(token, tempIndentationLevel, diagnosticRecords, ref onNewLine, lineHasPipelineBeforeToken, commentIndentationOffset); } break; } @@ -336,6 +339,30 @@ public override IEnumerable AnalyzeScript(Ast ast, string file return diagnosticRecords; } + private static int GetCommentRunIndentationOffset(Token[] tokens, int tokenIndex) + { + int firstCommentIndex = tokenIndex; + int currentLine = tokens[tokenIndex].Extent.StartLineNumber; + int precedingIndex = tokenIndex - 1; + while (precedingIndex >= 0 && tokens[precedingIndex].Kind == TokenKind.NewLine) + { + precedingIndex--; + if (precedingIndex < 0 || + tokens[precedingIndex].Kind != TokenKind.Comment || + tokens[precedingIndex].Extent.EndLineNumber != currentLine - 1) + { + break; + } + + firstCommentIndex = precedingIndex; + currentLine = tokens[precedingIndex].Extent.StartLineNumber; + precedingIndex--; + } + + return tokens[tokenIndex].Extent.StartColumnNumber - + tokens[firstCommentIndex].Extent.StartColumnNumber; + } + /// /// Scans forward from the current opener to the end of the line. /// Returns true if there is at least one unclosed opener when @@ -612,12 +639,14 @@ private void AddViolation( int expectedIndentationLevel, List diagnosticRecords, ref bool onNewLine, - bool lineHasPipelineBeforeToken = false) + bool lineHasPipelineBeforeToken = false, + int indentationOffset = 0) { if (onNewLine) { onNewLine = false; - if (token.Extent.StartColumnNumber - 1 != GetIndentation(expectedIndentationLevel)) + int expectedIndentation = Math.Max(0, GetIndentation(expectedIndentationLevel) + indentationOffset); + if (token.Extent.StartColumnNumber - 1 != expectedIndentation) { var fileName = token.Extent.File; var extent = token.Extent; @@ -640,14 +669,14 @@ private void AddViolation( GetDiagnosticSeverity(), fileName, null, - GetSuggestedCorrections(token, expectedIndentationLevel, lineHasPipelineBeforeToken))); + GetSuggestedCorrections(token, expectedIndentation, lineHasPipelineBeforeToken))); } } } private List GetSuggestedCorrections( Token token, - int indentationLevel, + int indentation, bool lineHasPipelineBeforeToken = false) { // TODO Add another constructor for correction extent that takes extent @@ -661,7 +690,7 @@ private List GetSuggestedCorrections( token.Extent.EndLineNumber, 1, token.Extent.EndColumnNumber, - GetIndentationString(indentationLevel) + optionalPipeline + token.Extent.Text, + new string(indentationChar, indentation) + optionalPipeline + token.Extent.Text, token.Extent.File)); return corrections; } diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index 6bf241116..ff40d3f79 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -206,6 +206,72 @@ function foo { Context "When a multi-line command is given" { + It 'Should preserve relative indentation in commented-out code with indentation' -TestCases @( + @{ Kind = 'space'; Indentation = ' ' } + @{ Kind = 'tab'; Indentation = "`t" } + ) { + param([string] $Kind, [string] $Indentation) + $scriptDefinition = @( + 'if ($a) {' + "$Indentation# if (`$b) {" + "$Indentation$Indentation# doThing" + "$Indentation# }" + "$($Indentation)Write-Output 'after'" + '}' + ) -join "`n" + $settings = @{ + IncludeRules = @('PSUseConsistentIndentation') + Rules = @{ + PSUseConsistentIndentation = @{ + Enable = $true + IndentationSize = 4 + PipelineIndentation = 'NoIndentation' + Kind = $Kind + } + } + } + + Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | + Should -Be $scriptDefinition + } + + It 'Should shift a commented-out code block without flattening it with indentation' -TestCases @( + @{ Kind = 'space'; Indentation = ' ' } + @{ Kind = 'tab'; Indentation = "`t" } + ) { + param([string] $Kind, [string] $Indentation) + $scriptDefinition = @( + 'if ($a) {' + '# if ($b) {' + "$Indentation# doThing" + '# }' + "$($Indentation)Write-Output 'after'" + '}' + ) -join "`n" + $expectedScriptDefinition = @( + 'if ($a) {' + "$Indentation# if (`$b) {" + "$Indentation$Indentation# doThing" + "$Indentation# }" + "$($Indentation)Write-Output 'after'" + '}' + ) -join "`n" + $settings = @{ + IncludeRules = @('PSUseConsistentIndentation') + Rules = @{ + PSUseConsistentIndentation = @{ + Enable = $true + IndentationSize = 4 + PipelineIndentation = 'NoIndentation' + Kind = $Kind + } + } + } + + Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | + Should -Be $expectedScriptDefinition + } + It "When a comment is in the middle of a multi-line statement with preceding and succeeding line continuations" { $scriptDefinition = @' foo ` From 9941989b0d6ef4b6dc304ee4dfb8fc8be908035a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 Oct 2026 22:06:12 +0000 Subject: [PATCH 03/17] Refine comment-run handling Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/UseConsistentIndentation.cs | 7 ++--- .../Rules/UseConsistentIndentation.tests.ps1 | 30 +++++-------------- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index a5020a04d..97c913db5 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -349,7 +349,8 @@ private static int GetCommentRunIndentationOffset(Token[] tokens, int tokenIndex precedingIndex--; if (precedingIndex < 0 || tokens[precedingIndex].Kind != TokenKind.Comment || - tokens[precedingIndex].Extent.EndLineNumber != currentLine - 1) + tokens[precedingIndex].Extent.EndLineNumber != currentLine - 1 || + (precedingIndex > 0 && tokens[precedingIndex - 1].Kind != TokenKind.NewLine)) { break; } @@ -706,9 +707,5 @@ private int GetIndentation(int indentationLevel) return indentationLevel * indentationLevelMultiplier; } - private string GetIndentationString(int indentationLevel) - { - return new string(indentationChar, GetIndentation(indentationLevel)); - } } } diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index ff40d3f79..3a0f325e2 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -204,7 +204,7 @@ function foo { } } - Context "When a multi-line command is given" { + Context "When a commented-out code block is provided" { It 'Should preserve relative indentation in commented-out code with indentation' -TestCases @( @{ Kind = 'space'; Indentation = ' ' } @@ -219,17 +219,8 @@ function foo { "$($Indentation)Write-Output 'after'" '}' ) -join "`n" - $settings = @{ - IncludeRules = @('PSUseConsistentIndentation') - Rules = @{ - PSUseConsistentIndentation = @{ - Enable = $true - IndentationSize = 4 - PipelineIndentation = 'NoIndentation' - Kind = $Kind - } - } - } + $settings.Rules.PSUseConsistentIndentation.Kind = $Kind + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | Should -Be $scriptDefinition @@ -256,22 +247,15 @@ function foo { "$($Indentation)Write-Output 'after'" '}' ) -join "`n" - $settings = @{ - IncludeRules = @('PSUseConsistentIndentation') - Rules = @{ - PSUseConsistentIndentation = @{ - Enable = $true - IndentationSize = 4 - PipelineIndentation = 'NoIndentation' - Kind = $Kind - } - } - } + $settings.Rules.PSUseConsistentIndentation.Kind = $Kind + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | Should -Be $expectedScriptDefinition } + } + Context "When a multi-line command is given" { It "When a comment is in the middle of a multi-line statement with preceding and succeeding line continuations" { $scriptDefinition = @' foo ` From 0c2d63043a33b6ce3457a7da7eb0ddd5de60e761 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 26 Oct 2026 11:18:39 +0000 Subject: [PATCH 04/17] Preserve relative indentation in comment runs (#2236) * Initial plan * Preserve indentation across comment runs Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/UseConsistentIndentation.cs | 15 ++++++++++++++- Tests/Rules/UseConsistentIndentation.tests.ps1 | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index 97c913db5..7c51b98f6 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -360,8 +360,21 @@ private static int GetCommentRunIndentationOffset(Token[] tokens, int tokenIndex precedingIndex--; } + int leastIndentedColumn = tokens[firstCommentIndex].Extent.StartColumnNumber; + for (int nextCommentIndex = firstCommentIndex + 2; + nextCommentIndex < tokens.Length && + tokens[nextCommentIndex - 1].Kind == TokenKind.NewLine && + tokens[nextCommentIndex].Kind == TokenKind.Comment && + tokens[nextCommentIndex].Extent.StartLineNumber == tokens[nextCommentIndex - 2].Extent.EndLineNumber + 1; + nextCommentIndex += 2) + { + leastIndentedColumn = Math.Min( + leastIndentedColumn, + tokens[nextCommentIndex].Extent.StartColumnNumber); + } + return tokens[tokenIndex].Extent.StartColumnNumber - - tokens[firstCommentIndex].Extent.StartColumnNumber; + leastIndentedColumn; } /// diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index 3a0f325e2..c6418ed49 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -253,6 +253,22 @@ function foo { Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | Should -Be $expectedScriptDefinition } + + It 'Should preserve indentation when the first comment is not the least-indented with indentation' -TestCases @( + @{ Kind = 'space'; Indentation = ' ' } + @{ Kind = 'tab'; Indentation = "`t" } + ) { + param([string] $Kind, [string] $Indentation) + $scriptDefinition = @( + "$Indentation# inner" + '# outer' + ) -join "`n" + $settings.Rules.PSUseConsistentIndentation.Kind = $Kind + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | + Should -Be $scriptDefinition + } } Context "When a multi-line command is given" { From 227ab25f2362412404feb49f1261086eca539893 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 26 Oct 2026 20:44:17 +0000 Subject: [PATCH 05/17] Preserve relative indentation in commented-out code (#2238) * Initial plan * Fix comment runs after line continuations Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> * Fix continuation indent after comment runs Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> * Include line continuations in comment scan Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> * Apply last suggestion 'Prevent double-counting indentation in comment runs' https://github.com/PowerShell/PSScriptAnalyzer/pull/2238#discussion_r4381470637 * Fix Pester discovery by removing extra BOM Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> Co-authored-by: Christoph Bergmeister --- Rules/UseConsistentIndentation.cs | 47 +++++++++----- .../Rules/UseConsistentIndentation.tests.ps1 | 65 +++++++++++++++++++ docs/Rules/UseConsistentIndentation.md | 3 + 3 files changed, 100 insertions(+), 15 deletions(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index 7c51b98f6..5fd573cc5 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -275,17 +275,15 @@ public override IEnumerable AnalyzeScript(Ast ast, string file ++tempIndentationLevel; } - // check for comments in between multi-line commands with line continuation + // Check for comments in between multi-line commands with line continuation. if (tokenIndex > 2 && tokens[tokenIndex - 1].Kind == TokenKind.NewLine && tokens[tokenIndex - 2].Kind == TokenKind.Comment) { - int searchForPrecedingLineContinuationIndex = tokenIndex - 2; - while (searchForPrecedingLineContinuationIndex > 0 && tokens[searchForPrecedingLineContinuationIndex].Kind == TokenKind.Comment) - { - searchForPrecedingLineContinuationIndex--; - } - - if (searchForPrecedingLineContinuationIndex >= 0 && tokens[searchForPrecedingLineContinuationIndex].Kind == TokenKind.LineContinuation) + GetCommentRunIndentationOffset( + tokens, + tokenIndex - 2, + out bool commentRunStartsAfterLineContinuation); + if (commentRunStartsAfterLineContinuation) { tempIndentationLevel++; } @@ -298,9 +296,17 @@ public override IEnumerable AnalyzeScript(Ast ast, string file } bool lineHasPipelineBeforeToken = LineHasPipelineBeforeToken(tokens, tokenIndex, token); - int commentIndentationOffset = token.Kind == TokenKind.Comment - ? GetCommentRunIndentationOffset(tokens, tokenIndex) - : 0; + int commentIndentationOffset = 0; + if (token.Kind == TokenKind.Comment) + { + commentIndentationOffset = GetCommentRunIndentationOffset( + tokens, + tokenIndex, + out bool commentRunStartsAfterLineContinuation); + tempIndentationLevel = indentationLevel + + (commentRunStartsAfterLineContinuation ? 1 : 0); + } + AddViolation(token, tempIndentationLevel, diagnosticRecords, ref onNewLine, lineHasPipelineBeforeToken, commentIndentationOffset); } break; @@ -339,18 +345,25 @@ public override IEnumerable AnalyzeScript(Ast ast, string file return diagnosticRecords; } - private static int GetCommentRunIndentationOffset(Token[] tokens, int tokenIndex) + private static int GetCommentRunIndentationOffset( + Token[] tokens, + int tokenIndex, + out bool commentRunStartsAfterLineContinuation) { int firstCommentIndex = tokenIndex; int currentLine = tokens[tokenIndex].Extent.StartLineNumber; int precedingIndex = tokenIndex - 1; - while (precedingIndex >= 0 && tokens[precedingIndex].Kind == TokenKind.NewLine) + while (precedingIndex >= 0 && + (tokens[precedingIndex].Kind == TokenKind.NewLine || + tokens[precedingIndex].Kind == TokenKind.LineContinuation)) { precedingIndex--; if (precedingIndex < 0 || tokens[precedingIndex].Kind != TokenKind.Comment || tokens[precedingIndex].Extent.EndLineNumber != currentLine - 1 || - (precedingIndex > 0 && tokens[precedingIndex - 1].Kind != TokenKind.NewLine)) + (precedingIndex > 0 && + tokens[precedingIndex - 1].Kind != TokenKind.NewLine && + tokens[precedingIndex - 1].Kind != TokenKind.LineContinuation)) { break; } @@ -360,10 +373,14 @@ private static int GetCommentRunIndentationOffset(Token[] tokens, int tokenIndex precedingIndex--; } + commentRunStartsAfterLineContinuation = + firstCommentIndex > 0 && + tokens[firstCommentIndex - 1].Kind == TokenKind.LineContinuation; int leastIndentedColumn = tokens[firstCommentIndex].Extent.StartColumnNumber; for (int nextCommentIndex = firstCommentIndex + 2; nextCommentIndex < tokens.Length && - tokens[nextCommentIndex - 1].Kind == TokenKind.NewLine && + (tokens[nextCommentIndex - 1].Kind == TokenKind.NewLine || + tokens[nextCommentIndex - 1].Kind == TokenKind.LineContinuation) && tokens[nextCommentIndex].Kind == TokenKind.Comment && tokens[nextCommentIndex].Extent.StartLineNumber == tokens[nextCommentIndex - 2].Extent.EndLineNumber + 1; nextCommentIndex += 2) diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index c6418ed49..6febc02c7 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -254,6 +254,20 @@ function foo { Should -Be $expectedScriptDefinition } + It 'Should preserve relative indentation in comments after a line continuation' { + $scriptDefinition = @' +Write-Output ` + # first + # nested + # last + -InputObject 'value' +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | + Should -Be $scriptDefinition + } + It 'Should preserve indentation when the first comment is not the least-indented with indentation' -TestCases @( @{ Kind = 'space'; Indentation = ' ' } @{ Kind = 'tab'; Indentation = "`t" } @@ -269,6 +283,57 @@ function foo { Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | Should -Be $scriptDefinition } + + It 'Should preserve a comment run containing an internal line continuation with indentation' -TestCases @( + @{ Kind = 'space'; Indentation = ' ' } + @{ Kind = 'tab'; Indentation = "`t" } + ) { + param([string] $Kind, [string] $Indentation) + $scriptDefinition = @( + '<# first #> `' + "$Indentation<# second #>" + "Write-Output 'after'" + ) -join "`n" + $settings.Rules.PSUseConsistentIndentation.Kind = $Kind + + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $scriptDefinition -Settings $settings + $violations.Count | Should -Be 0 + $formatted = Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings + $formatted | Should -Be $scriptDefinition + Invoke-Formatter -ScriptDefinition $formatted -Settings $settings | + Should -Be $formatted + } + + It 'Should shift a comment run containing an internal line continuation uniformly with indentation' -TestCases @( + @{ Kind = 'space'; Indentation = ' ' } + @{ Kind = 'tab'; Indentation = "`t" } + ) { + param([string] $Kind, [string] $Indentation) + $scriptDefinition = @( + 'if ($a) {' + '<# first #> `' + "$Indentation<# second #>" + "$($Indentation)Write-Output 'after'" + '}' + ) -join "`n" + $expectedScriptDefinition = @( + 'if ($a) {' + "$Indentation<# first #> ``" + "$Indentation$Indentation<# second #>" + "$($Indentation)Write-Output 'after'" + '}' + ) -join "`n" + $settings.Rules.PSUseConsistentIndentation.Kind = $Kind + + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $scriptDefinition -Settings $settings + $violations.Count | Should -Be 2 + $formatted = Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings + $formatted | Should -Be $expectedScriptDefinition + Invoke-Formatter -ScriptDefinition $formatted -Settings $settings | + Should -Be $formatted + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $formatted -Settings $settings + $violations.Count | Should -Be 0 + } } Context "When a multi-line command is given" { diff --git a/docs/Rules/UseConsistentIndentation.md b/docs/Rules/UseConsistentIndentation.md index 5e6392772..4d020bbd4 100644 --- a/docs/Rules/UseConsistentIndentation.md +++ b/docs/Rules/UseConsistentIndentation.md @@ -15,6 +15,9 @@ title: UseConsistentIndentation This rule detects inconsistent indentation patterns within a source file. Indentation should be consistent throughout your script. +Consecutive comment lines are shifted together to preserve their relative indentation, including +when a line continuation occurs within the comment run. + ## Example ### Noncompliant From b028aaf2a5b6f5d51835393bf93bb6365c40bc37 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 26 Oct 2026 21:44:42 +0000 Subject: [PATCH 06/17] Preserve comment indentation after pipelines with PipelineIndentation=None (#2241) * Initial plan * Fix comment indentation after skipped pipelines Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> * Fix inconsistent indentation in UseConsistentIndentation tests Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> Co-authored-by: Christoph Bergmeister Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- Rules/UseConsistentIndentation.cs | 17 ++++++++++++++--- Tests/Rules/UseConsistentIndentation.tests.ps1 | 13 +++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index 5fd573cc5..0e6680e63 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -282,7 +282,8 @@ public override IEnumerable AnalyzeScript(Ast ast, string file GetCommentRunIndentationOffset( tokens, tokenIndex - 2, - out bool commentRunStartsAfterLineContinuation); + out bool commentRunStartsAfterLineContinuation, + out _); if (commentRunStartsAfterLineContinuation) { tempIndentationLevel++; @@ -302,7 +303,14 @@ public override IEnumerable AnalyzeScript(Ast ast, string file commentIndentationOffset = GetCommentRunIndentationOffset( tokens, tokenIndex, - out bool commentRunStartsAfterLineContinuation); + out bool commentRunStartsAfterLineContinuation, + out bool commentRunStartsAfterPipeline); + if (pipelineIndentationStyle == PipelineIndentationStyle.None && + commentRunStartsAfterPipeline) + { + onNewLine = false; + continue; + } tempIndentationLevel = indentationLevel + (commentRunStartsAfterLineContinuation ? 1 : 0); } @@ -348,7 +356,8 @@ public override IEnumerable AnalyzeScript(Ast ast, string file private static int GetCommentRunIndentationOffset( Token[] tokens, int tokenIndex, - out bool commentRunStartsAfterLineContinuation) + out bool commentRunStartsAfterLineContinuation, + out bool commentRunStartsAfterPipeline) { int firstCommentIndex = tokenIndex; int currentLine = tokens[tokenIndex].Extent.StartLineNumber; @@ -376,6 +385,8 @@ private static int GetCommentRunIndentationOffset( commentRunStartsAfterLineContinuation = firstCommentIndex > 0 && tokens[firstCommentIndex - 1].Kind == TokenKind.LineContinuation; + commentRunStartsAfterPipeline = + PreviousLineEndedWithPipe(tokens, firstCommentIndex, tokens[firstCommentIndex]); int leastIndentedColumn = tokens[firstCommentIndex].Extent.StartColumnNumber; for (int nextCommentIndex = firstCommentIndex + 2; nextCommentIndex < tokens.Length && diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index 6febc02c7..d07a7b0a5 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -661,6 +661,19 @@ foo | Test-CorrectionExtentFromContent @params } + It "Should preserve indentation in a comment run after a pipeline with PipelineIndentation None" { + $def = @' +foo | + # first comment + # second comment +bar +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'None' + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings + $violations | Should -BeNullOrEmpty + Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should -Be $def + } + It "Should indent properly after line continuation (backtick) character with pipeline" { $def = @' foo | From 075fdbb7070199a58e82510c6896f3f3ab0ac5d8 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Oct 2026 05:10:10 +0000 Subject: [PATCH 07/17] Exclude inline-code block comments from comment indentation runs (#2243) * Initial plan * Exclude inline code comments from comment runs Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> * Refactor HasCodeAfterCommentOnSameLine method Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fix comment helper compilation error Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> * Preserve pipeline context through comment continuations Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> * Avoid inheriting pipeline context from trailing comments Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> Co-authored-by: Christoph Bergmeister Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- Rules/UseConsistentIndentation.cs | 36 ++++++++++++++ .../Rules/UseConsistentIndentation.tests.ps1 | 49 +++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index 0e6680e63..2dedf530a 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -359,6 +359,30 @@ private static int GetCommentRunIndentationOffset( out bool commentRunStartsAfterLineContinuation, out bool commentRunStartsAfterPipeline) { + commentRunStartsAfterLineContinuation = false; + commentRunStartsAfterPipeline = false; + if (HasCodeAfterCommentOnSameLine(tokens, tokenIndex)) + { + commentRunStartsAfterLineContinuation = + tokenIndex > 0 && + tokens[tokenIndex - 1].Kind == TokenKind.LineContinuation; + if (tokenIndex > 2 && + (tokens[tokenIndex - 1].Kind == TokenKind.NewLine || + tokens[tokenIndex - 1].Kind == TokenKind.LineContinuation) && + tokens[tokenIndex - 2].Kind == TokenKind.Comment && + (tokens[tokenIndex - 3].Kind == TokenKind.NewLine || + tokens[tokenIndex - 3].Kind == TokenKind.LineContinuation)) + { + GetCommentRunIndentationOffset( + tokens, + tokenIndex - 2, + out _, + out commentRunStartsAfterPipeline); + } + + return 0; + } + int firstCommentIndex = tokenIndex; int currentLine = tokens[tokenIndex].Extent.StartLineNumber; int precedingIndex = tokenIndex - 1; @@ -369,6 +393,7 @@ private static int GetCommentRunIndentationOffset( precedingIndex--; if (precedingIndex < 0 || tokens[precedingIndex].Kind != TokenKind.Comment || + HasCodeAfterCommentOnSameLine(tokens, precedingIndex) || tokens[precedingIndex].Extent.EndLineNumber != currentLine - 1 || (precedingIndex > 0 && tokens[precedingIndex - 1].Kind != TokenKind.NewLine && @@ -393,6 +418,7 @@ private static int GetCommentRunIndentationOffset( (tokens[nextCommentIndex - 1].Kind == TokenKind.NewLine || tokens[nextCommentIndex - 1].Kind == TokenKind.LineContinuation) && tokens[nextCommentIndex].Kind == TokenKind.Comment && + !HasCodeAfterCommentOnSameLine(tokens, nextCommentIndex) && tokens[nextCommentIndex].Extent.StartLineNumber == tokens[nextCommentIndex - 2].Extent.EndLineNumber + 1; nextCommentIndex += 2) { @@ -405,6 +431,16 @@ private static int GetCommentRunIndentationOffset( leastIndentedColumn; } + private static bool HasCodeAfterCommentOnSameLine(Token[] tokens, int commentIndex) + { + Token nextToken = NextTokenIgnoringComments(tokens, commentIndex); + return nextToken != null && + nextToken.Kind != TokenKind.NewLine && + nextToken.Kind != TokenKind.LineContinuation && + nextToken.Kind != TokenKind.EndOfInput && + nextToken.Extent.StartLineNumber <= tokens[commentIndex].Extent.EndLineNumber; + } + /// /// Scans forward from the current opener to the end of the line. /// Returns true if there is at least one unclosed opener when diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index d07a7b0a5..a48cf33c5 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -284,6 +284,25 @@ Write-Output ` Should -Be $scriptDefinition } + It 'Should not include a block comment followed by code in a comment run' { + $scriptDefinition = @' +if ($a) { + # comment + <# note #> Write-Output 'value' +} +'@ + $expectedScriptDefinition = @' +if ($a) { + # comment + <# note #> Write-Output 'value' +} +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | + Should -Be $expectedScriptDefinition + } + It 'Should preserve a comment run containing an internal line continuation with indentation' -TestCases @( @{ Kind = 'space'; Indentation = ' ' } @{ Kind = 'tab'; Indentation = "`t" } @@ -674,6 +693,36 @@ bar Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should -Be $def } + It "Should preserve pipeline indentation across a comment line continuation with PipelineIndentation None" { + $def = @' +foo | + <# comment #> ` + <# note #> bar +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'None' + Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should -Be $def + } + + It "Should not inherit pipeline indentation from a trailing comment with PipelineIndentation None" { + $def = @' +function test { + foo | bar # trailing + <# note #> baz +} +'@ + $expected = @' +function test { + foo | bar # trailing + <# note #> baz +} +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'None' + $violations = Invoke-ScriptAnalyzer -ScriptDefinition $def -Settings $settings + $violations.Count | Should -Be 1 + Invoke-Formatter -ScriptDefinition $def -Settings $settings | Should -Be $expected + Invoke-Formatter -ScriptDefinition $expected -Settings $settings | Should -Be $expected + } + It "Should indent properly after line continuation (backtick) character with pipeline" { $def = @' foo | From be6251da27d224f6cae1e742ea3ea7d92d34d016 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Oct 2026 09:24:04 +0000 Subject: [PATCH 08/17] Preserve continuation indentation before block-comment-prefixed arguments (#2247) * Initial plan * Fix continued comment argument indentation Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/UseConsistentIndentation.cs | 3 ++- Tests/Rules/UseConsistentIndentation.tests.ps1 | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index 2dedf530a..4dc2ed6ca 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -376,8 +376,9 @@ private static int GetCommentRunIndentationOffset( GetCommentRunIndentationOffset( tokens, tokenIndex - 2, - out _, + out bool precedingCommentRunStartsAfterLineContinuation, out commentRunStartsAfterPipeline); + commentRunStartsAfterLineContinuation |= precedingCommentRunStartsAfterLineContinuation; } return 0; diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index a48cf33c5..cd295dca8 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -268,6 +268,18 @@ Write-Output ` Should -Be $scriptDefinition } + It 'Should preserve continuation indentation before a block-comment-prefixed argument' { + $scriptDefinition = @' +Write-Output ` + # comment + <# note #> -InputObject 'value' +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | + Should -Be $scriptDefinition + } + It 'Should preserve indentation when the first comment is not the least-indented with indentation' -TestCases @( @{ Kind = 'space'; Indentation = ' ' } @{ Kind = 'tab'; Indentation = "`t" } From 0e5eb9f53f7f0c05ba767130e0fd335dd3598ba6 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Oct 2026 11:30:26 +0000 Subject: [PATCH 09/17] Handle multiple comments per line in indentation runs (#2249) * Initial plan * Handle multiple comments per line in comment runs Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> * Fix adjacent comment continuation indentation Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/UseConsistentIndentation.cs | 76 ++++++++++++++----- .../Rules/UseConsistentIndentation.tests.ps1 | 39 ++++++++++ 2 files changed, 96 insertions(+), 19 deletions(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index 4dc2ed6ca..b36e2c91f 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -387,6 +387,14 @@ private static int GetCommentRunIndentationOffset( int firstCommentIndex = tokenIndex; int currentLine = tokens[tokenIndex].Extent.StartLineNumber; int precedingIndex = tokenIndex - 1; + while (precedingIndex >= 0 && + tokens[precedingIndex].Kind == TokenKind.Comment && + tokens[precedingIndex].Extent.StartLineNumber == currentLine) + { + firstCommentIndex = precedingIndex; + precedingIndex--; + } + while (precedingIndex >= 0 && (tokens[precedingIndex].Kind == TokenKind.NewLine || tokens[precedingIndex].Kind == TokenKind.LineContinuation)) @@ -395,17 +403,32 @@ private static int GetCommentRunIndentationOffset( if (precedingIndex < 0 || tokens[precedingIndex].Kind != TokenKind.Comment || HasCodeAfterCommentOnSameLine(tokens, precedingIndex) || - tokens[precedingIndex].Extent.EndLineNumber != currentLine - 1 || - (precedingIndex > 0 && - tokens[precedingIndex - 1].Kind != TokenKind.NewLine && - tokens[precedingIndex - 1].Kind != TokenKind.LineContinuation)) + tokens[precedingIndex].Extent.EndLineNumber != currentLine - 1) { break; } - firstCommentIndex = precedingIndex; - currentLine = tokens[precedingIndex].Extent.StartLineNumber; - precedingIndex--; + int previousCommentLine = tokens[precedingIndex].Extent.StartLineNumber; + int firstCommentOnPreviousLine = precedingIndex; + int precedingCommentIndex = precedingIndex - 1; + while (precedingCommentIndex >= 0 && + tokens[precedingCommentIndex].Kind == TokenKind.Comment && + tokens[precedingCommentIndex].Extent.StartLineNumber == previousCommentLine) + { + firstCommentOnPreviousLine = precedingCommentIndex; + precedingCommentIndex--; + } + + if (precedingCommentIndex >= 0 && + tokens[precedingCommentIndex].Kind != TokenKind.NewLine && + tokens[precedingCommentIndex].Kind != TokenKind.LineContinuation) + { + break; + } + + firstCommentIndex = firstCommentOnPreviousLine; + currentLine = previousCommentLine; + precedingIndex = precedingCommentIndex; } commentRunStartsAfterLineContinuation = @@ -413,19 +436,34 @@ private static int GetCommentRunIndentationOffset( tokens[firstCommentIndex - 1].Kind == TokenKind.LineContinuation; commentRunStartsAfterPipeline = PreviousLineEndedWithPipe(tokens, firstCommentIndex, tokens[firstCommentIndex]); - int leastIndentedColumn = tokens[firstCommentIndex].Extent.StartColumnNumber; - for (int nextCommentIndex = firstCommentIndex + 2; - nextCommentIndex < tokens.Length && - (tokens[nextCommentIndex - 1].Kind == TokenKind.NewLine || - tokens[nextCommentIndex - 1].Kind == TokenKind.LineContinuation) && - tokens[nextCommentIndex].Kind == TokenKind.Comment && - !HasCodeAfterCommentOnSameLine(tokens, nextCommentIndex) && - tokens[nextCommentIndex].Extent.StartLineNumber == tokens[nextCommentIndex - 2].Extent.EndLineNumber + 1; - nextCommentIndex += 2) + int leastIndentedColumn = int.MaxValue; + int nextCommentIndex = firstCommentIndex; + while (nextCommentIndex < tokens.Length && + tokens[nextCommentIndex].Kind == TokenKind.Comment) { - leastIndentedColumn = Math.Min( - leastIndentedColumn, - tokens[nextCommentIndex].Extent.StartColumnNumber); + int currentCommentLine = tokens[nextCommentIndex].Extent.StartLineNumber; + while (nextCommentIndex < tokens.Length && + tokens[nextCommentIndex].Kind == TokenKind.Comment && + tokens[nextCommentIndex].Extent.StartLineNumber == currentCommentLine) + { + leastIndentedColumn = Math.Min( + leastIndentedColumn, + tokens[nextCommentIndex].Extent.StartColumnNumber); + nextCommentIndex++; + } + + if (nextCommentIndex + 1 >= tokens.Length || + (tokens[nextCommentIndex].Kind != TokenKind.NewLine && + tokens[nextCommentIndex].Kind != TokenKind.LineContinuation) || + tokens[nextCommentIndex + 1].Kind != TokenKind.Comment || + HasCodeAfterCommentOnSameLine(tokens, nextCommentIndex + 1) || + tokens[nextCommentIndex + 1].Extent.StartLineNumber != + tokens[nextCommentIndex - 1].Extent.EndLineNumber + 1) + { + break; + } + + nextCommentIndex++; } return tokens[tokenIndex].Extent.StartColumnNumber - diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index cd295dca8..18439de07 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -268,6 +268,19 @@ Write-Output ` Should -Be $scriptDefinition } + It 'Should preserve indentation when a comment-only line contains multiple block comments' { + $scriptDefinition = @' +if ($a) { + <# first #> <# second #> + # nested +} +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | + Should -Be $scriptDefinition + } + It 'Should preserve continuation indentation before a block-comment-prefixed argument' { $scriptDefinition = @' Write-Output ` @@ -280,6 +293,32 @@ Write-Output ` Should -Be $scriptDefinition } + It 'Should preserve continuation indentation after multiple inline block comments' { + $scriptDefinition = @' +Write-Output ` + <# first #> <# second #> + -InputObject 'value' +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | + Should -Be $scriptDefinition + } + + It 'Should preserve indentation with many adjacent block comments' { + $comments = (1..16 | ForEach-Object { "<# comment $_ #>" }) -join ' ' + $scriptDefinition = @( + 'if ($a) {' + " $comments" + ' # nested' + '}' + ) -join "`n" + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | + Should -Be $scriptDefinition + } + It 'Should preserve indentation when the first comment is not the least-indented with indentation' -TestCases @( @{ Kind = 'space'; Indentation = ' ' } @{ Kind = 'tab'; Indentation = "`t" } From 2e1c903a13241f57fdd7ccc9ef26d3f7bf5eb744 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Oct 2026 11:49:59 +0000 Subject: [PATCH 10/17] Handle block comment boundaries in indentation runs Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/UseConsistentIndentation.cs | 66 +++++++++++++------ .../Rules/UseConsistentIndentation.tests.ps1 | 38 +++++++++++ 2 files changed, 85 insertions(+), 19 deletions(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index b36e2c91f..e347256e5 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -279,9 +279,18 @@ public override IEnumerable AnalyzeScript(Ast ast, string file if (tokenIndex > 2 && tokens[tokenIndex - 1].Kind == TokenKind.NewLine && tokens[tokenIndex - 2].Kind == TokenKind.Comment) { + int precedingCommentIndex = tokenIndex - 2; + while (precedingCommentIndex > 0 && + tokens[precedingCommentIndex - 1].Kind == TokenKind.Comment && + tokens[precedingCommentIndex - 1].Extent.EndLineNumber >= + tokens[precedingCommentIndex].Extent.StartLineNumber) + { + precedingCommentIndex--; + } + GetCommentRunIndentationOffset( tokens, - tokenIndex - 2, + precedingCommentIndex, out bool commentRunStartsAfterLineContinuation, out _); if (commentRunStartsAfterLineContinuation) @@ -366,19 +375,30 @@ private static int GetCommentRunIndentationOffset( commentRunStartsAfterLineContinuation = tokenIndex > 0 && tokens[tokenIndex - 1].Kind == TokenKind.LineContinuation; - if (tokenIndex > 2 && - (tokens[tokenIndex - 1].Kind == TokenKind.NewLine || - tokens[tokenIndex - 1].Kind == TokenKind.LineContinuation) && - tokens[tokenIndex - 2].Kind == TokenKind.Comment && - (tokens[tokenIndex - 3].Kind == TokenKind.NewLine || - tokens[tokenIndex - 3].Kind == TokenKind.LineContinuation)) + int precedingCommentIndex = tokenIndex - 1; + if (precedingCommentIndex >= 0 && + (tokens[precedingCommentIndex].Kind == TokenKind.NewLine || + tokens[precedingCommentIndex].Kind == TokenKind.LineContinuation)) { - GetCommentRunIndentationOffset( - tokens, - tokenIndex - 2, - out bool precedingCommentRunStartsAfterLineContinuation, - out commentRunStartsAfterPipeline); - commentRunStartsAfterLineContinuation |= precedingCommentRunStartsAfterLineContinuation; + precedingCommentIndex--; + if (precedingCommentIndex >= 0 && + tokens[precedingCommentIndex].Kind == TokenKind.Comment) + { + while (precedingCommentIndex > 0 && + tokens[precedingCommentIndex - 1].Kind == TokenKind.Comment && + tokens[precedingCommentIndex - 1].Extent.EndLineNumber >= + tokens[precedingCommentIndex].Extent.StartLineNumber) + { + precedingCommentIndex--; + } + + GetCommentRunIndentationOffset( + tokens, + precedingCommentIndex, + out bool precedingCommentRunStartsAfterLineContinuation, + out commentRunStartsAfterPipeline); + commentRunStartsAfterLineContinuation |= precedingCommentRunStartsAfterLineContinuation; + } } return 0; @@ -389,12 +409,15 @@ private static int GetCommentRunIndentationOffset( int precedingIndex = tokenIndex - 1; while (precedingIndex >= 0 && tokens[precedingIndex].Kind == TokenKind.Comment && - tokens[precedingIndex].Extent.StartLineNumber == currentLine) + (tokens[precedingIndex].Extent.StartLineNumber == currentLine || + tokens[precedingIndex].Extent.EndLineNumber >= + tokens[firstCommentIndex].Extent.StartLineNumber)) { firstCommentIndex = precedingIndex; precedingIndex--; } + currentLine = tokens[firstCommentIndex].Extent.StartLineNumber; while (precedingIndex >= 0 && (tokens[precedingIndex].Kind == TokenKind.NewLine || tokens[precedingIndex].Kind == TokenKind.LineContinuation)) @@ -413,7 +436,9 @@ private static int GetCommentRunIndentationOffset( int precedingCommentIndex = precedingIndex - 1; while (precedingCommentIndex >= 0 && tokens[precedingCommentIndex].Kind == TokenKind.Comment && - tokens[precedingCommentIndex].Extent.StartLineNumber == previousCommentLine) + (tokens[precedingCommentIndex].Extent.StartLineNumber == previousCommentLine || + tokens[precedingCommentIndex].Extent.EndLineNumber >= + tokens[firstCommentOnPreviousLine].Extent.StartLineNumber)) { firstCommentOnPreviousLine = precedingCommentIndex; precedingCommentIndex--; @@ -427,7 +452,7 @@ private static int GetCommentRunIndentationOffset( } firstCommentIndex = firstCommentOnPreviousLine; - currentLine = previousCommentLine; + currentLine = tokens[firstCommentOnPreviousLine].Extent.StartLineNumber; precedingIndex = precedingCommentIndex; } @@ -441,14 +466,17 @@ private static int GetCommentRunIndentationOffset( while (nextCommentIndex < tokens.Length && tokens[nextCommentIndex].Kind == TokenKind.Comment) { - int currentCommentLine = tokens[nextCommentIndex].Extent.StartLineNumber; + int currentCommentEndLine = tokens[nextCommentIndex].Extent.EndLineNumber; while (nextCommentIndex < tokens.Length && tokens[nextCommentIndex].Kind == TokenKind.Comment && - tokens[nextCommentIndex].Extent.StartLineNumber == currentCommentLine) + tokens[nextCommentIndex].Extent.StartLineNumber <= currentCommentEndLine) { leastIndentedColumn = Math.Min( leastIndentedColumn, tokens[nextCommentIndex].Extent.StartColumnNumber); + currentCommentEndLine = Math.Max( + currentCommentEndLine, + tokens[nextCommentIndex].Extent.EndLineNumber); nextCommentIndex++; } @@ -458,7 +486,7 @@ private static int GetCommentRunIndentationOffset( tokens[nextCommentIndex + 1].Kind != TokenKind.Comment || HasCodeAfterCommentOnSameLine(tokens, nextCommentIndex + 1) || tokens[nextCommentIndex + 1].Extent.StartLineNumber != - tokens[nextCommentIndex - 1].Extent.EndLineNumber + 1) + currentCommentEndLine + 1) { break; } diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index 18439de07..cf54dda64 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -305,6 +305,44 @@ Write-Output ` Should -Be $scriptDefinition } + It 'Should preserve continuation indentation after multiple block comments before an argument' { + $scriptDefinition = @' +Write-Output ` + <# first #> <# second #> + <# note #> -InputObject 'value' +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | + Should -Be $scriptDefinition + } + + It 'Should preserve pipeline context after multiple block comments before an argument' { + $scriptDefinition = @' +Write-Output | + <# first #> <# second #> + <# note #> -InputObject 'value' +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | + Should -Be $scriptDefinition + } + + It 'Should preserve nested indentation across a multiline block comment' { + $scriptDefinition = @' +if ($a) { + <# first + #> <# second #> + # nested +} +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | + Should -Be $scriptDefinition + } + It 'Should preserve indentation with many adjacent block comments' { $comments = (1..16 | ForEach-Object { "<# comment $_ #>" }) -join ' ' $scriptDefinition = @( From 7d8d8414f1d3f49b799b8d93cbde3f554e7be9e3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Oct 2026 12:20:29 +0000 Subject: [PATCH 11/17] Fix pipeline context for inline comments Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/UseConsistentIndentation.cs | 5 ++++- Tests/Rules/UseConsistentIndentation.tests.ps1 | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index e347256e5..c2dcb8688 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -606,7 +606,10 @@ private static bool PipelineIsFollowedByNewlineOrLineContinuation(Token[] tokens private static bool PreviousLineEndedWithPipe(Token[] tokens, int tokenIndex, Token token) { - if (tokenIndex < 2 || token.Extent.StartLineNumber == 1) + if (tokenIndex < 2 || + (tokens[tokenIndex - 1].Kind != TokenKind.NewLine && + tokens[tokenIndex - 1].Kind != TokenKind.LineContinuation) || + token.Extent.StartLineNumber == 1) { return false; } diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index cf54dda64..75b0e099c 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -323,7 +323,7 @@ Write-Output | <# first #> <# second #> <# note #> -InputObject 'value' '@ - $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'None' Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | Should -Be $scriptDefinition From 984815c7342c5e3d7e0c96b21fcd5dc8c8e2261d Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Oct 2026 13:45:51 +0000 Subject: [PATCH 12/17] Prevent repeated indentation of multiline comment runs (#2251) * Initial plan * Fix repeated comment-run indentation Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/UseConsistentIndentation.cs | 10 +++++++--- Tests/Rules/UseConsistentIndentation.tests.ps1 | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index c2dcb8688..f60a05d64 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -466,14 +466,18 @@ private static int GetCommentRunIndentationOffset( while (nextCommentIndex < tokens.Length && tokens[nextCommentIndex].Kind == TokenKind.Comment) { + int firstCommentInGroup = nextCommentIndex; int currentCommentEndLine = tokens[nextCommentIndex].Extent.EndLineNumber; while (nextCommentIndex < tokens.Length && tokens[nextCommentIndex].Kind == TokenKind.Comment && tokens[nextCommentIndex].Extent.StartLineNumber <= currentCommentEndLine) { - leastIndentedColumn = Math.Min( - leastIndentedColumn, - tokens[nextCommentIndex].Extent.StartColumnNumber); + if (nextCommentIndex == firstCommentInGroup) + { + leastIndentedColumn = Math.Min( + leastIndentedColumn, + tokens[nextCommentIndex].Extent.StartColumnNumber); + } currentCommentEndLine = Math.Max( currentCommentEndLine, tokens[nextCommentIndex].Extent.EndLineNumber); diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index 75b0e099c..39a8b1ecc 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -343,6 +343,22 @@ if ($a) { Should -Be $scriptDefinition } + It 'Should not increase indentation across a multiline block comment when repeatedly formatted' { + $scriptDefinition = @' +if ($a) { + <# first +#> <# second #> + # nested +} +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + $formatted = Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings + $formatted | Should -Be $scriptDefinition + Invoke-Formatter -ScriptDefinition $formatted -Settings $settings | + Should -Be $scriptDefinition + } + It 'Should preserve indentation with many adjacent block comments' { $comments = (1..16 | ForEach-Object { "<# comment $_ #>" }) -join ' ' $scriptDefinition = @( From 067cbda5b01bb9a6deb859be32924d59e51b3848 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:48:52 +0000 Subject: [PATCH 13/17] [WIP] Fix issue with preserving relative indentation in comments (#2253) * Initial plan * Fix multiline comment group detection Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/UseConsistentIndentation.cs | 10 ++++++++- .../Rules/UseConsistentIndentation.tests.ps1 | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index f60a05d64..0985f39e1 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -505,11 +505,19 @@ private static int GetCommentRunIndentationOffset( private static bool HasCodeAfterCommentOnSameLine(Token[] tokens, int commentIndex) { Token nextToken = NextTokenIgnoringComments(tokens, commentIndex); + int commentGroupEndLine = tokens[commentIndex].Extent.EndLineNumber; + for (int i = commentIndex + 1; i < tokens.Length && + tokens[i].Kind == TokenKind.Comment && + tokens[i].Extent.StartLineNumber <= commentGroupEndLine; i++) + { + commentGroupEndLine = Math.Max(commentGroupEndLine, tokens[i].Extent.EndLineNumber); + } + return nextToken != null && nextToken.Kind != TokenKind.NewLine && nextToken.Kind != TokenKind.LineContinuation && nextToken.Kind != TokenKind.EndOfInput && - nextToken.Extent.StartLineNumber <= tokens[commentIndex].Extent.EndLineNumber; + nextToken.Extent.StartLineNumber <= commentGroupEndLine; } /// diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index 39a8b1ecc..e01df4cfd 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -408,6 +408,27 @@ if ($a) { Should -Be $expectedScriptDefinition } + It 'Should not include a multiline block-comment group followed by code in a comment run' { + $scriptDefinition = @' +if ($a) { + # comment +<# first #> <# second +#> Write-Output 'value' +} +'@ + $expectedScriptDefinition = @' +if ($a) { + # comment + <# first #> <# second +#> Write-Output 'value' +} +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | + Should -Be $expectedScriptDefinition + } + It 'Should preserve a comment run containing an internal line continuation with indentation' -TestCases @( @{ Kind = 'space'; Indentation = ' ' } @{ Kind = 'tab'; Indentation = "`t" } From 91e54c2c4cdd9611af554ed356852143c450d62b Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Tue, 27 Oct 2026 17:25:16 +0000 Subject: [PATCH 14/17] Exclude trailing inline comments from comment runs (#2255) Add a regression test for standalone comments following trailing inline comments.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/UseConsistentIndentation.cs | 18 ++++++++++++++++++ .../Rules/UseConsistentIndentation.tests.ps1 | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index 0985f39e1..74f3602d6 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -426,6 +426,7 @@ private static int GetCommentRunIndentationOffset( if (precedingIndex < 0 || tokens[precedingIndex].Kind != TokenKind.Comment || HasCodeAfterCommentOnSameLine(tokens, precedingIndex) || + HasCodeBeforeCommentOnSameLine(tokens, precedingIndex) || tokens[precedingIndex].Extent.EndLineNumber != currentLine - 1) { break; @@ -520,6 +521,23 @@ private static bool HasCodeAfterCommentOnSameLine(Token[] tokens, int commentInd nextToken.Extent.StartLineNumber <= commentGroupEndLine; } + private static bool HasCodeBeforeCommentOnSameLine(Token[] tokens, int commentIndex) + { + int commentStartLine = tokens[commentIndex].Extent.StartLineNumber; + int precedingIndex = commentIndex - 1; + while (precedingIndex >= 0 && + tokens[precedingIndex].Kind == TokenKind.Comment && + tokens[precedingIndex].Extent.EndLineNumber >= commentStartLine) + { + precedingIndex--; + } + + return precedingIndex >= 0 && + tokens[precedingIndex].Kind != TokenKind.NewLine && + tokens[precedingIndex].Kind != TokenKind.LineContinuation && + tokens[precedingIndex].Extent.EndLineNumber == commentStartLine; + } + /// /// Scans forward from the current opener to the end of the line. /// Returns true if there is at least one unclosed opener when diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index e01df4cfd..dd3c04a6a 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -408,6 +408,25 @@ if ($a) { Should -Be $expectedScriptDefinition } + It 'Should not include a trailing inline comment in the following comment run' { + $scriptDefinition = @' +function test { + $value = 1 # trailing + # standalone +} +'@ + $expectedScriptDefinition = @' +function test { + $value = 1 # trailing + # standalone +} +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings | + Should -Be $expectedScriptDefinition + } + It 'Should not include a multiline block-comment group followed by code in a comment run' { $scriptDefinition = @' if ($a) { From 4069f2aa2dbaa04dd129adbca20a9a084ae6c13b Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Tue, 27 Oct 2026 17:50:42 +0000 Subject: [PATCH 15/17] Add tests for handling comment run boundaries and indentation resets --- .../Rules/UseConsistentIndentation.tests.ps1 | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index dd3c04a6a..e178a146d 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -254,6 +254,70 @@ function foo { Should -Be $expectedScriptDefinition } + It 'Should treat a blank line as a boundary between comment runs with indentation' -TestCases @( + @{ Kind = 'space'; Indentation = ' ' } + @{ Kind = 'tab'; Indentation = "`t" } + ) { + param([string] $Kind, [string] $Indentation) + $scriptDefinition = @( + 'if ($a) {' + "$Indentation# first" + "$Indentation$Indentation# nested" + '' + "$Indentation$Indentation# second" + "$Indentation$Indentation$Indentation# nested" + '}' + ) -join "`n" + $expectedScriptDefinition = @( + 'if ($a) {' + "$Indentation# first" + "$Indentation$Indentation# nested" + '' + "$Indentation# second" + "$Indentation$Indentation# nested" + '}' + ) -join "`n" + $settings.Rules.PSUseConsistentIndentation.Kind = $Kind + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + $formatted = Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings + $formatted | Should -Be $expectedScriptDefinition + Invoke-Formatter -ScriptDefinition $formatted -Settings $settings | + Should -Be $expectedScriptDefinition + } + + It 'Should restart comment-run indentation after executable code with indentation' -TestCases @( + @{ Kind = 'space'; Indentation = ' ' } + @{ Kind = 'tab'; Indentation = "`t" } + ) { + param([string] $Kind, [string] $Indentation) + $scriptDefinition = @( + 'if ($a) {' + "$Indentation# first" + "$Indentation$Indentation# nested" + "${Indentation}Write-Output 'between'" + "$Indentation$Indentation# second" + "$Indentation$Indentation$Indentation# nested" + '}' + ) -join "`n" + $expectedScriptDefinition = @( + 'if ($a) {' + "$Indentation# first" + "$Indentation$Indentation# nested" + "${Indentation}Write-Output 'between'" + "$Indentation# second" + "$Indentation$Indentation# nested" + '}' + ) -join "`n" + $settings.Rules.PSUseConsistentIndentation.Kind = $Kind + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + + $formatted = Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings + $formatted | Should -Be $expectedScriptDefinition + Invoke-Formatter -ScriptDefinition $formatted -Settings $settings | + Should -Be $expectedScriptDefinition + } + It 'Should preserve relative indentation in comments after a line continuation' { $scriptDefinition = @' Write-Output ` From 3f33813376f425a543dc612f70b391f8a2c01a4d Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Oct 2026 18:15:59 +0000 Subject: [PATCH 16/17] Preserve relative indentation in commented-out code (#2257) * Initial plan * Exclude trailing pipe comments from comment runs Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/UseConsistentIndentation.cs | 5 ++++ .../Rules/UseConsistentIndentation.tests.ps1 | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Rules/UseConsistentIndentation.cs b/Rules/UseConsistentIndentation.cs index 74f3602d6..7fc98509d 100644 --- a/Rules/UseConsistentIndentation.cs +++ b/Rules/UseConsistentIndentation.cs @@ -404,6 +404,11 @@ private static int GetCommentRunIndentationOffset( return 0; } + if (HasCodeBeforeCommentOnSameLine(tokens, tokenIndex)) + { + return 0; + } + int firstCommentIndex = tokenIndex; int currentLine = tokens[tokenIndex].Extent.StartLineNumber; int precedingIndex = tokenIndex - 1; diff --git a/Tests/Rules/UseConsistentIndentation.tests.ps1 b/Tests/Rules/UseConsistentIndentation.tests.ps1 index e178a146d..81c90d324 100644 --- a/Tests/Rules/UseConsistentIndentation.tests.ps1 +++ b/Tests/Rules/UseConsistentIndentation.tests.ps1 @@ -932,6 +932,31 @@ function test { Invoke-Formatter -ScriptDefinition $expected -Settings $settings | Should -Be $expected } + It "Should exclude a trailing comment after a line-leading pipe from comment runs" { + $def = @' +function test { + foo ` + | # trailing +# standalone + bar +} +'@ + $expected = @' +function test { + foo ` + | # trailing + # standalone + bar +} +'@ + $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation' + $formatted = Invoke-Formatter -ScriptDefinition $def -Settings $settings + + $formatted | Should -Be $expected + Invoke-Formatter -ScriptDefinition $formatted -Settings $settings | + Should -Be $expected + } + It "Should indent properly after line continuation (backtick) character with pipeline" { $def = @' foo | From 27e6f68f8d08b5aa6417408520b812a5005bd7bf Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Oct 2026 18:41:36 +0000 Subject: [PATCH 17/17] test: cover comment indentation in pipelines (#2260) Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> 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 |