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 — Add file-path support to Invoke-Formatter by Copilot · Pull Request #2230 · PowerShell/PSScriptAnalyzer

Conversation

Copilot AI commented Oct 22, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Invoke-Formatter currently accepts script text only. Add a file-based parameter set that formats files in place while retaining their encoding, line endings, and indentation style.

  • File formatting: Add -Path; keep -ScriptDefinition and its existing parameter behavior.
  • File properties: Detect encoding and line endings, and infer tabs or spaces when no indentation kind is explicitly configured. Respect -WhatIf.
  • Example:
    Invoke-Formatter -Path ./script.ps1
  • Fixes Add -Path parameter to Invoke-Formatter #775

Sorry, something went wrong.

Uh oh!

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

All reactions
Initial plan
82848f3
Copilot AI assigned Copilot and Christoph Bergmeister (bergmeister) Oct 22, 2026
Copilot started work on behalf of Christoph Bergmeister (bergmeister) October 22, 2026 21:59
View session
Copilot AI linked an issue Oct 22, 2026 that may be closed by this pull request
Add -Path parameter to Invoke-Formatter #775
Open
@bergmeister
Add Path support to Invoke-Formatter
ab19dd5
Co-authored-by: bergmeister <[email protected]>
Copilot AI changed the title [WIP] Add -Path parameter to Invoke-Formatter Add file-path support to Invoke-Formatter Oct 22, 2026
Copilot finished work on behalf of Christoph Bergmeister (bergmeister) October 22, 2026 22:09
Copilot AI requested a review from Christoph Bergmeister (bergmeister) October 22, 2026 22:09
@bergmeister
Christoph Bergmeister (bergmeister) added this pull request to stack #2233 October 22, 2026 23:15
@bergmeister
Christoph Bergmeister (bergmeister) removed this pull request from stack #2233 October 22, 2026 23:18
@bergmeister
Document Invoke-Formatter confirmation parameters (#2232)
a69865a
* Document formatter confirmation parameters

Co-authored-by: bergmeister <[email protected]>

* Handle pipeline binding help values in tests

Co-authored-by: bergmeister <[email protected]>

* Clarify -Confirm and -WhatIf parameter descriptions

Updated descriptions for -Confirm and -WhatIf parameters to clarify their effects when using the Path and ScriptDefinition options.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: bergmeister <[email protected]>
Co-authored-by: Christoph Bergmeister <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@bergmeister
Christoph Bergmeister (bergmeister) requested a balanced review from Copilot October 23, 2026 06:50
Copilot started reviewing on behalf of Christoph Bergmeister (bergmeister) October 23, 2026 06:50
View session
Copilot AI reviewed Oct 23, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

🟡 Changes recommended

Encoding handling can alter or corrupt files, and indentation inference can incorrectly change their style.

3 open issues
  • High severity Use BOM-less strict UTF-8 fallback to prevent file corruption · New
  • Medium severity Avoid leaking inferred indentation style across files · New
  • Medium severity Ignore blank lines and multiline payloads when inferring indentation · New
What changed in this PR

Adds in-place file formatting to Invoke-Formatter for issue #775, while retaining the existing script-text parameter set.

Changes:

  • Adds -Path, file-property detection, indentation inference, and -WhatIf support.
  • Adds file-formatting tests and updates pipeline-input help checks.
  • Documents file formatting and confirmation behavior.
File Description
Tests/​Engine/​ModuleHelp.Tests.ps1 Updates checks for pipeline-binding help metadata.
Tests/​Engine/​InvokeFormatter.tests.ps1 Tests file formatting, encoding, indentation, and -WhatIf.
Engine/​Commands/​InvokeFormatterCommand.cs Implements path-based formatting and file-property handling.
docs/​Cmdlets/​Invoke-Formatter.md Documents the new parameter set and usage.

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Engine/Commands/InvokeFormatterCommand.cs Resolved

Uh oh!

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

Comment thread Engine/Commands/InvokeFormatterCommand.cs Resolved

Uh oh!

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

Comment thread Engine/Commands/InvokeFormatterCommand.cs Resolved

Uh oh!

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

Copilot started work on behalf of Christoph Bergmeister (bergmeister) October 23, 2026 07:06
View session
@bergmeister
Fix formatter indentation inference
deb58bc
Co-authored-by: bergmeister <[email protected]>
Copilot finished work on behalf of Christoph Bergmeister (bergmeister) October 23, 2026 07:18
@bergmeister
Improve encoding reading and indentation inference
6dc79da
Refactor encoding handling and indentation logic.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@bergmeister
Christoph Bergmeister (bergmeister) requested a balanced review from Copilot October 23, 2026 07:39
Copilot started reviewing on behalf of Christoph Bergmeister (bergmeister) October 23, 2026 07:40
View session
Copilot AI reviewed Oct 23, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

🟡 Changes recommended

BOM-less legacy-encoded scripts fail to format, leaving the encoding-preservation requirement unmet.

1 open issue
  • Medium severity Support explicit or fallback encodings for BOM-less scripts · New
1 previously missed issue

In code that hasn't changed since last review

Low severity Correct help syntax and parameter set declarations

docs/​Cmdlets/​Invoke-Formatter.md:21

The help source does not represent the new mutually exclusive parameter sets correctly: both invocations share one unnamed syntax block, and -ScriptDefinition still declares Parameter Sets: (All) at line 145. This file feeds New-ExternalHelp in build.psm1:65, so these declarations also affect generated help. Give ScriptDefinition (Default) and Path separate ### headings and syntax blocks, following docs/Cmdlets/Invoke-ScriptAnalyzer.md:16–53, and change the ScriptDefinition parameter metadata to Parameter Sets: ScriptDefinition.

3 resolved since last review
  • High severity Use BOM-less strict UTF-8 fallback to prevent file corruption
  • Medium severity Ignore blank lines and multiline payloads when inferring indentation
  • Medium severity Avoid leaking inferred indentation style across files

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Engine/Commands/InvokeFormatterCommand.cs Resolved

Uh oh!

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

Copilot started work on behalf of Christoph Bergmeister (bergmeister) October 23, 2026 07:48
View session
@bergmeister
Support explicit encodings in file formatting
e113020
Co-authored-by: bergmeister <[email protected]>
Copilot finished work on behalf of Christoph Bergmeister (bergmeister) October 23, 2026 07:54
Copilot started work on behalf of Christoph Bergmeister (bergmeister) October 23, 2026 07:56
View session
@bergmeister
Remove formatter encoding parameter
d0ba92d
Co-authored-by: bergmeister <[email protected]>
Copilot finished work on behalf of Christoph Bergmeister (bergmeister) October 23, 2026 08:01
@bergmeister
Christoph Bergmeister (bergmeister) requested a balanced review from Copilot October 23, 2026 08:04
Copilot started reviewing on behalf of Christoph Bergmeister (bergmeister) October 23, 2026 08:04
View session
Copilot AI reviewed Oct 23, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

🟡 Changes recommended

CR-only files encounter a formatting failure, and the legacy-encoding regression is not portable across supported Windows PowerShell environments.

3 open issues
  • High severity CR-only line endings cause indentation inference failure · New
  • Medium severity Windows-1252 fixture fails on other ANSI code pages · New
  • Medium severity BOM-less UTF-8 literals break under Windows PowerShell · New
1 resolved since last review
  • Medium severity Support explicit or fallback encodings for BOM-less scripts

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Engine/Commands/InvokeFormatterCommand.cs Outdated
int spaceIndentedLines = 0;
string firstIndentationKind = "space";
bool foundIndentation = false;
string[] lines = scriptDefinition.Split('\n');
Comment thread Tests/Engine/InvokeFormatter.tests.ps1
[System.IO.File]::ReadAllBytes($path)[0..1] | Should -Be @(255, 254)
}

It 'Best-effort formats BOM-less files using a legacy encoding' {
Comment thread Tests/Engine/InvokeFormatter.tests.ps1 Outdated
Comment on lines +59 to +60
$scriptDefinition = '$name=''café'''
$expected = '$name = ''café'''
@bergmeister
Christoph Bergmeister (bergmeister) added this pull request to stack #2235 October 23, 2026 10:25
Copilot AI mentioned this pull request Oct 23, 2026
Preserve CR-only line endings when formatting files #2234
Merged
@bergmeister
Christoph Bergmeister (bergmeister) removed this pull request from stack #2235 October 23, 2026 17:45
@bergmeister
Preserve CR-only line endings when formatting files (#2234)
ae4cac8
* Initial plan

* Handle CR-only formatter line endings

Co-authored-by: bergmeister <[email protected]>

* Make legacy encoding fixture source-independent

Co-authored-by: bergmeister <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: bergmeister <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@bergmeister Christoph Bergmeister (bergmeister) Awaiting requested review from bergmeister bergmeister is a code owner
@michaeltlombardi Mikey Lombardi (He/Him) (michaeltlombardi) Awaiting requested review from michaeltlombardi michaeltlombardi will be requested when the pull request is marked ready for review michaeltlombardi is a code owner

At least 1 approving review is required to merge this pull request.

Uh oh!

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

Assignees

@bergmeister Christoph Bergmeister (bergmeister)

Copilot code review Copilot

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Add -Path parameter to Invoke-Formatter

Uh oh!

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

3 participants

@bergmeister
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.