Skip to content

Preserve relative indentation in commented-out code - #2257

Merged
Christoph Bergmeister (bergmeister) merged 2 commits into
copilot/fix-psuseconsistentindentation-issuefrom
copilot/preserve-relative-indentation-comments
Oct 27, 2026
Merged

Christoph Bergmeister (bergmeister) merged 2 commits into
copilot/fix-psuseconsistentindentation-issuefrom
copilot/preserve-relative-indentation-comments

Conversation

Copilot AI commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Thanks for the feedback on #2231. I've created this new PR, which merges into #2231, to address your comment. I will work on the changes and keep this PR's description up to date as I make progress.

Original PR: #2231
Triggering comment (#2231 (comment)):

🔵 Needs a closer look

Inline comments after line-leading pipes can still join standalone comment runs and incorrectly shift pipeline indentation.

No open issues 🎉

1 previously missed issue
In code that hasn't changed since last review

Medium severity Exclude trailing comments from pipeline indentation offset calculation
Rules/​UseConsistentIndentation.cs:373

With PipelineIndentation = 'NoIndentation', a line-leading pipe's trailing comment reaches this scan and is incorrectly grouped with following standalone comments. For a function containing a four-space-indented, backtick-continued foo, then | # trailing, # standalone, and bar, formatting moves the pipe from column 5 to column 11. Exclude comments with code before them as well as code after them from run-offset calculation.

Review effort: Balanced

Copilot fix and add regression test. create new pr instead of pushing to this branch

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
@bergmeister Christoph Bergmeister (bergmeister) changed the title [WIP] Preserve relative indentation in commented-out code Preserve relative indentation in commented-out code 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.

🟢 Approval recommended

The narrow guard addresses the reported defect with focused regression coverage; tests were not executed during review.

No open issues 🎉

What changed in this PR

This PR fixes a comment-run boundary case in PSUseConsistentIndentation, supporting #2231’s preservation of relative indentation in commented-out code.

Changes:

  • Exclude comments with preceding code on the same line from comment-run offset calculation.
  • Add a regression test for trailing comments after line-leading pipes, checking expected formatting and idempotence.
File Description
Tests/​Rules/​UseConsistentIndentation.tests.ps1 Tests the reported pipeline case with NoIndentation and repeat formatting.
Rules/​UseConsistentIndentation.cs Adds an early return for comments preceded by code on the same line.

Review effort: Balanced

@bergmeister
Christoph Bergmeister (bergmeister) marked this pull request as ready for review October 27, 2026 18:15
@bergmeister
Christoph Bergmeister (bergmeister) merged commit 3f33813 into copilot/fix-psuseconsistentindentation-issue Oct 27, 2026
8 checks passed
@bergmeister
Christoph Bergmeister (bergmeister) deleted the copilot/preserve-relative-indentation-comments branch October 27, 2026 18:16
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