GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Improve pipeline indentation handling in UseConsistentIndentation rule by liamjpeters · Pull Request #2173 · PowerShell/PSScriptAnalyzer

Conversation

@liamjpeters

@liamjpeters Liam Peters (liamjpeters) commented Apr 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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.

    1. 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).

    2. 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.

  • Small improvements in the UseConsistentIndentation rule's handling of indentation where opening braces are on the same line. Previously, adjacent openers like .foreach({, @(@{, or ([PSCustomObject]@{ each incremented the indentation level, producing double or triple indentation. Now only the last unclosed opener on a line affects indentation, fixing common patterns like .foreach({...}) and $list.Add([PSCustomObject]@{...}).

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

Fixes #1680
Fixes #1933
Fixes #2159

Potentially also Fixes the main issue raised in #1168

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .cs, .ps1 and .psm1 files have the correct copyright header
  • Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@liamjpeters
Improve pipeline indentation handling in UseConsistentIndentation rule
ab4a695
@liamjpeters
Liam Peters (liamjpeters) requested review from a team and Christoph Bergmeister (bergmeister) as code owners April 2, 2026 12:22
Liam Peters (liamjpeters) added 3 commits April 3, 2026 10:41
@liamjpeters
Merge branch 'main' into PowerShell#1933-PipelineIndentationIssue
2af0dae
@liamjpeters
Fix over-indentation when multiple openers appear on the same line
d89d877
@liamjpeters
Merge branch 'PowerShell#1933-PipelineIndentationIssue' of https://gi…
b470da8
…thub.com/liamjpeters/PSScriptAnalyzer into PowerShell#1933-PipelineIndentationIssue
andyleejordan
Andy Jordan (andyleejordan) approved these changes May 4, 2026
View reviewed changes

@andyleejordan Andy Jordan (andyleejordan) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Nice work — this hits #1933, #1680, and #2159 with one coherent change.

The two structural moves are exactly the ones the bugs called for:

  • Replacing the flat currentIndentationLevelIncreaseDueToPipelines counter with a Dictionary<PipelineAst, int> so each pipeline's contribution is unwound only when that pipeline ends — that's the actual fix for the runaway-indent-on-nested-pipelines bug.
  • The end-position sort on pipelineAsts so inner pipelines are matched before outer ones (and the comment explaining why MatchingPipelineAstEnd's early-break needs that ordering) is a nice clarity improvement.

The unification of paren/curly opener handling under a single openerSkippedIndentation stack with HasUnclosedOpenerBeforeLineEnd is a clean refactor of the previous lParenSkippedIndentation-only logic, and the depth-relative scan (return false on our own closer, true on a nested unclosed opener at line end) is correct for the multiple-openers-on-a-line cases. All 90 tests pass locally.

LGTM — approving.

— Drafted by Copilot (Claude Opus 4.7)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@andyleejordan
Andy Jordan (andyleejordan) merged commit d97ddd4 into PowerShell:main May 4, 2026
4 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@liamjpeters
Liam Peters (liamjpeters) deleted the #1933-PipelineIndentationIssue branch May 5, 2026 07:35
@steve02081504 steve green (steve02081504) mentioned this pull request Sep 18, 2026
PSUseConsistentIndentation double-indents attribute bodies that open a scriptblock ([Attr({ … })]) #2216
Closed
2 tasks done
Copilot AI mentioned this pull request Oct 27, 2026
Add regression tests for attribute scriptblock indentation ([Attr({ … })]) #2263
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bergmeister Christoph Bergmeister (bergmeister) Awaiting requested review from bergmeister bergmeister is a code owner
1 more reviewer
@andyleejordan Andy Jordan (andyleejordan) andyleejordan approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

PSUseConsistentIndentation: Hashtable inside method call gets double-indented Invoke-Formatter: indent a block even though it should not Incorrect Multi-line Pipeline Indentation when inside a Scriptblock that also has a Pipeline

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@liamjpeters @andyleejordan
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.