Allow user to force the default implicit formatting to use AutoSize - #28018
Open
Dongbo Wang (daxian-dbw) wants to merge 2 commits into
Open
Dongbo Wang (daxian-dbw) wants to merge 2 commits into
Dongbo Wang (daxian-dbw) wants to merge 2 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Copilot started reviewing on behalf of
Dongbo Wang (daxian-dbw)
September 16, 2026 01:07
View session
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Critical formatting defects and missing regression coverage must be addressed before approval.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds $PSStyle.AutoSizeDefaultFormatting to enable AutoSize for implicit table and wide formatting.
Changes:
- Adds the new
$PSStylesetting. - Applies it during default formatting.
- Adds formatting tests.
File summaries
| File | Review findings |
|---|---|
test/powershell/engine/Formatting/PSStyle.Tests.ps1 |
Moderate (3 votes): Add coverage for implicit wide views and untyped objects. Moderate (1 vote): Restore the original process-wide setting in cleanup rather than hard-coding $false. |
src/System.Management.Automation/FormatAndOutput/format-default/format-default.cs |
Critical (3 votes): Preserve null parameters during shape inference for objects without default views. Critical (3 votes): Apply the override only to selected Table or Wide views to avoid buffering List and Complex output. |
src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs |
Nit (1 vote): Include AutoSizeDefaultFormatting in the default $PSStyle formatter view. |
Review details
Suppressed comments (2)
src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs:647
- The default
PSStyleview is an explicitListControlthat enumerates the top-level settings (PowerShellCore_format_ps1xml.cs:2139-2212), but it has no entry forAutoSizeDefaultFormatting. As a result,$PSStyleand$PSStyle | Format-Listhide this new user-facing setting; add it to the generated default formatter view.
public bool AutoSizeDefaultFormatting { get; set; }
test/powershell/engine/Formatting/PSStyle.Tests.ps1:624
- The cleanup hard-codes
$falseinstead of restoring the value present when the test started. BecausePSStyle.Instanceis process-wide and the surrounding tests save and restore settings (for example, lines 143-153), this can leak state to later tests and makes the test depend on an initially disabled feature. Save the original value, establish a false baseline before capturing$defaultOutput, and restore the original infinally.
$PSStyle.AutoSizeDefaultFormatting = $false
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+32
to
+33
| var parameters = new FormattingCommandLineParameters { autosize = true }; | ||
| ((InnerFormatShapeCommand)this.implementation).SetCommandLineParameters(parameters); |
Comment on lines
+32
to
+33
| var parameters = new FormattingCommandLineParameters { autosize = true }; | ||
| ((InnerFormatShapeCommand)this.implementation).SetCommandLineParameters(parameters); |
Comment on lines
+606
to
+610
| It "Force default formatting to use 'AutoSize'" { | ||
| try { | ||
| $defaultOutput = Get-Command Import-Module | Out-String | ||
| $PSStyle.AutoSizeDefaultFormatting = $true | ||
| $autoSizedOutput = Get-Command Import-Module | Out-String |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR Summary
Allow user to force the default implicit formatting to use
AutoSize. When$PSStyle.AutoSizeDefaultFormatting = $true, the default implicit formatting applied by PowerShell (viaOut-Default) will enforceAutoSizewhen the chosen formatting view istableorwide, similar to runningFormat-Table -AutoSizeandFormat-Wide -AutoSizeexplicitly.This allows PowerShell to generate less verbose output when used by an agent. It also makes PowerShell works better with small-window terminal.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header