Skip to content

Handle multiple comments per line in indentation runs - #2249

Merged
Christoph Bergmeister (bergmeister) merged 3 commits into
copilot/fix-psuseconsistentindentation-issuefrom
copilot/fix-code-review-comment
Oct 27, 2026
Merged

Christoph Bergmeister (bergmeister) merged 3 commits into
copilot/fix-psuseconsistentindentation-issuefrom
copilot/fix-code-review-comment

Conversation

Copilot AI commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Comment-run scanning assumed one comment token per line, so adjacent block comments could split a run and flatten the indentation of a following comment.

  • Scanner: Traverse all comment tokens on each comment-only line in both scan directions.
  • Regression: Cover adjacent block comments followed by a more-indented comment:
    if ($a) {
        <# first #> <# second #>
            # nested
    }

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code based on review comment Handle multiple comments per line in indentation runs Oct 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Continuation indentation remains incorrect for following arguments, and the backward scan adds avoidable quadratic work.

2 open issues
What changed in this PR

This PR updates the indentation formatter to preserve relative comment indentation when a comment-only line contains multiple adjacent block comments.

Changes:

  • Scan adjacent comment tokens in both directions when identifying comment runs.
  • Add a regression test for adjacent block comments followed by a more-indented comment.
File Description
Tests/​Rules/​UseConsistentIndentation.tests.ps1 Adds coverage for preserving indentation after adjacent block comments.
Rules/​UseConsistentIndentation.cs Expands comment-run scanning to handle multiple comments per line.

Review effort: Balanced

Comment thread Rules/UseConsistentIndentation.cs
Comment thread Rules/UseConsistentIndentation.cs
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused scanner changes and regression coverage address the reported behavior with no unresolved blocking issues.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@bergmeister
Christoph Bergmeister (bergmeister) marked this pull request as ready for review October 27, 2026 11:30
@bergmeister
Christoph Bergmeister (bergmeister) merged commit 0e5eb9f into copilot/fix-psuseconsistentindentation-issue Oct 27, 2026
8 checks passed
@bergmeister
Christoph Bergmeister (bergmeister) deleted the copilot/fix-code-review-comment branch October 27, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants