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" }