Skip to content

Add regression tests for attribute scriptblock indentation ([Attr({ … })]) - #2263

Open
Christoph Bergmeister (bergmeister) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-double-indent-attribute-bodies
Open

Christoph Bergmeister (bergmeister) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-double-indent-attribute-bodies

Conversation

Copilot AI commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

In 1.25.0, PSUseConsistentIndentation double-indents the body of an attribute that opens a scriptblock, such as [ArgumentCompleter({ … })] or [ValidateScript({ … })]. The body gets two levels and the closing })] gets one.

# 1.25.0 output
[ArgumentCompleter({
		Param($commandName, $parameterName)
	})]

# Expected (current main)
[ArgumentCompleter({
	Param($commandName, $parameterName)
})]

Root cause / status

Changes

  • Tests only, no rule changes. Two cases are added to the "When multiple openers appear on the same line" context in Tests/Rules/UseConsistentIndentation.tests.ps1:

    • top-level [ArgumentCompleter({ … })], using the issue's example
    • [ValidateScript({ … })] nested inside a function's param() block

    Both start from double-indented input and check that it is corrected. They fail against 1.25.0, so a regression would be caught.

….. })])

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.

🟢 Approval recommended

No active review issues were identified for the added attribute scriptblock indentation regression tests.

No open issues 🎉

What changed in this PR

Adds regression coverage for attribute scriptblock indentation reported in #2216, protecting the existing fix from #2173 without changing rule behavior.

Changes:

  • Tests correction of double-indented bodies and closing delimiters in top-level [ArgumentCompleter({ … })].
  • Tests the same correction for [ValidateScript({ … })] nested inside a function’s param() block.
File Description
Tests/​Rules/​UseConsistentIndentation.tests.ps1 Adds two attribute scriptblock cases to the multiple-openers indentation tests.

Review effort: Balanced

@bergmeister
Christoph Bergmeister (bergmeister) marked this pull request as ready for review October 28, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants