Skip to content

Exclude inline-code block comments from comment indentation runs - #2243

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

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

Conversation

Copilot AI commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor
  • Problem: A block comment followed by executable code on the same line could be treated as part of an adjacent standalone comment run, producing an incorrect indentation offset.
  • Change: Exclude such comments from run membership and offset calculations, preserving the executable line’s indentation.
if ($a) {
    # comment
        <# note #> Write-Output 'value'
}

The inline-comment line should be corrected to four spaces of indentation.

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code based on review comment Exclude inline-code block comments from comment indentation runs Oct 26, 2026
@bergmeister
Christoph Bergmeister (bergmeister) marked this pull request as ready for review October 26, 2026 21:05
@bergmeister

Copy link
Copy Markdown
Collaborator

Copilot change this pr to a stacked pr because otherwise test suite won't run

Copilot AI commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Christoph Bergmeister (@bergmeister) I've opened a new pull request, #2244, to work on those changes. Once the pull request is ready, I'll request review from you.

@bergmeister
Christoph Bergmeister (bergmeister) marked this pull request as ready for review October 26, 2026 21:08

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

The new logic loses continuation indentation and misses executable lines with multiple leading block comments.

2 open issues
What changed in this PR

This PR updates the indentation formatter to exclude block comments followed by same-line code from standalone comment runs, so executable lines receive normal indentation.

Changes:

  • Adds same-line code checks when calculating comment-run membership and offsets.
  • Adds a regression test for an over-indented executable line following a standalone comment.
File Description
Tests/​Rules/​UseConsistentIndentation.tests.ps1 Tests indentation of a block comment followed by executable code.
Rules/​UseConsistentIndentation.cs Excludes comments with following same-line code from comment-run calculations.

Review effort: Balanced

Comment thread Rules/UseConsistentIndentation.cs
Comment thread Rules/UseConsistentIndentation.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

🟡 Changes recommended

Pipeline indentation preservation regresses when an inline-code comment follows a standalone block comment separated by a line continuation.

1 open issue
2 resolved since last review

Review effort: Balanced

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.

🔵 Needs a closer look

Trailing comments can incorrectly propagate pipeline context and prevent indentation correction of an independent command.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Avoid inheriting pipeline context from trailing comments

Rules/​UseConsistentIndentation.cs:372

With PipelineIndentation = 'None', a function containing foo | bar # trailing followed by <# note #> baz leaves the independent baz command at eight spaces instead of correcting it to four. This condition accepts the trailing comment, so the recursive call incorrectly inherits pipeline context from the earlier pipe. Only inherit context from comments that start standalone lines, and add a regression test for this case.

1 resolved since last review

Review effort: Balanced

@bergmeister

Copy link
Copy Markdown
Collaborator

Copilot fix this last unresolved review comment
Avoid inheriting pipeline context from trailing comments
Rules/​UseConsistentIndentation.cs:372

With PipelineIndentation = 'None', a function containing foo | bar # trailing followed by <# note #> baz leaves the independent baz command at eight spaces instead of correcting it to four. This condition accepts the trailing comment, so the recursive call incorrectly inherits pipeline context from the earlier pipe. Only inherit context from comments that start standalone lines, and add a regression test for this case.

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>

Copilot AI commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Copilot fix this last unresolved review comment
Avoid inheriting pipeline context from trailing comments
Rules/​UseConsistentIndentation.cs:372
...

Fixed in 80a3db7. Pipeline context is inherited only from comments that start standalone lines. Added the regression test; all 105 indentation tests pass, and CodeQL reports no alerts.

Copilot change this pr to a stacked pr because otherwise test suite won't run

Confirmed this PR is already stacked on copilot/fix-psuseconsistentindentation-issue. Its latest CI Tests run passed.

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.

🔵 Needs a closer look

The interaction between inherited continuation context and executable-line indentation needs human validation before approval.

No open issues 🎉

Review effort: Balanced

@bergmeister
Christoph Bergmeister (bergmeister) marked this pull request as ready for review October 27, 2026 05:09
@bergmeister
Christoph Bergmeister (bergmeister) merged commit 075fdbb into copilot/fix-psuseconsistentindentation-issue Oct 27, 2026
8 checks passed
@bergmeister
Christoph Bergmeister (bergmeister) deleted the copilot/fix-code-review-suggestion branch October 27, 2026 05:10
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