Skip to content

Commit 80e81ec

Browse files
Copilotbergmeister
andauthored
Exclude trailing pipe comments from comment runs
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
1 parent 4d7ae16 commit 80e81ec

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎Rules/UseConsistentIndentation.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ private static int GetCommentRunIndentationOffset(
404404
return 0;
405405
}
406406

407+
if (HasCodeBeforeCommentOnSameLine(tokens, tokenIndex))
408+
{
409+
return 0;
410+
}
411+
407412
int firstCommentIndex = tokenIndex;
408413
int currentLine = tokens[tokenIndex].Extent.StartLineNumber;
409414
int precedingIndex = tokenIndex - 1;

‎Tests/Rules/UseConsistentIndentation.tests.ps1‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,31 @@ function test {
932932
Invoke-Formatter -ScriptDefinition $expected -Settings $settings | Should -Be $expected
933933
}
934934

935+
It "Should exclude a trailing comment after a line-leading pipe from comment runs" {
936+
$def = @'
937+
function test {
938+
foo `
939+
| # trailing
940+
# standalone
941+
bar
942+
}
943+
'@
944+
$expected = @'
945+
function test {
946+
foo `
947+
| # trailing
948+
# standalone
949+
bar
950+
}
951+
'@
952+
$settings.Rules.PSUseConsistentIndentation.PipelineIndentation = 'NoIndentation'
953+
$formatted = Invoke-Formatter -ScriptDefinition $def -Settings $settings
954+
955+
$formatted | Should -Be $expected
956+
Invoke-Formatter -ScriptDefinition $formatted -Settings $settings |
957+
Should -Be $expected
958+
}
959+
935960
It "Should indent properly after line continuation (backtick) character with pipeline" {
936961
$def = @'
937962
foo |

0 commit comments

Comments
 (0)