Skip to content

Improve pipeline indentation handling in UseConsistentIndentation rule#2173

Open
liamjpeters wants to merge 2 commits intoPowerShell:mainfrom
liamjpeters:#1933-PipelineIndentationIssue
Open

Improve pipeline indentation handling in UseConsistentIndentation rule#2173
liamjpeters wants to merge 2 commits intoPowerShell:mainfrom
liamjpeters:#1933-PipelineIndentationIssue

Conversation

@liamjpeters
Copy link
Copy Markdown
Contributor

PR Summary

Two small improvements in the UseConsistentIndentation rule's handing of pipeline indentation. Flagged in this issue and issue comment.

  • Rule never finds the ends of nested pipelines, as it had a fast-return when it reached a pipeline who's end position was beyond the current tokens line. It would always find the outer/parent pipeline (which contains the nested pipeline and spans past it) and return early, empty-handed.

    This would lead to some cases of "runaway" indents.

    PR sorts the pipelines, in place, by their end line number and column number. This allows the nested pipeline to be found first (as they end before their parent pipeline).

  • Rule was using a single counter to keep track of pipeline indentation and then removing it all when it found a pipeline end.

    There were some edge cases that were, even with the first issue resolved, not quite right.

    PR adds in tracking of each pipeline's indentation contribution separately.

Copilot generated (and I reviewed) a bunch of tests to cover these cases. It's really getting quite good at generating tests now 🤖

Fixes #1933

PR Checklist

@liamjpeters liamjpeters requested review from a team and bergmeister as code owners April 2, 2026 12:22
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.

Invoke-Formatter: indent a block even though it should not

1 participant