File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -466,14 +466,18 @@ private static int GetCommentRunIndentationOffset(
466466 while ( nextCommentIndex < tokens . Length &&
467467 tokens [ nextCommentIndex ] . Kind == TokenKind . Comment )
468468 {
469+ int firstCommentInGroup = nextCommentIndex ;
469470 int currentCommentEndLine = tokens [ nextCommentIndex ] . Extent . EndLineNumber ;
470471 while ( nextCommentIndex < tokens . Length &&
471472 tokens [ nextCommentIndex ] . Kind == TokenKind . Comment &&
472473 tokens [ nextCommentIndex ] . Extent . StartLineNumber <= currentCommentEndLine )
473474 {
474- leastIndentedColumn = Math . Min (
475- leastIndentedColumn ,
476- tokens [ nextCommentIndex ] . Extent . StartColumnNumber ) ;
475+ if ( nextCommentIndex == firstCommentInGroup )
476+ {
477+ leastIndentedColumn = Math . Min (
478+ leastIndentedColumn ,
479+ tokens [ nextCommentIndex ] . Extent . StartColumnNumber ) ;
480+ }
477481 currentCommentEndLine = Math . Max (
478482 currentCommentEndLine ,
479483 tokens [ nextCommentIndex ] . Extent . EndLineNumber ) ;
Original file line number Diff line number Diff line change @@ -343,6 +343,22 @@ if ($a) {
343343 Should - Be $scriptDefinition
344344 }
345345
346+ It ' Should not increase indentation across a multiline block comment when repeatedly formatted' {
347+ $scriptDefinition = @'
348+ if ($a) {
349+ <# first
350+ #> <# second #>
351+ # nested
352+ }
353+ '@
354+ $settings.Rules.PSUseConsistentIndentation.PipelineIndentation = ' NoIndentation'
355+
356+ $formatted = Invoke-Formatter - ScriptDefinition $scriptDefinition - Settings $settings
357+ $formatted | Should - Be $scriptDefinition
358+ Invoke-Formatter - ScriptDefinition $formatted - Settings $settings |
359+ Should - Be $scriptDefinition
360+ }
361+
346362 It ' Should preserve indentation with many adjacent block comments' {
347363 $comments = (1 .. 16 | ForEach-Object { " <# comment $_ #>" }) -join ' '
348364 $scriptDefinition = @ (
You can’t perform that action at this time.
0 commit comments