You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Exclude inline-code block comments from comment indentation runs - #2243
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.
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.
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
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The inline-comment line should be corrected to four spaces of indentation.