Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Rules/UseConsistentIndentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions Tests/Rules/UseConsistentIndentation.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
Loading