Skip to content

Preserve DSC resource names during alias correction - #2270

Draft
Christoph Bergmeister (bergmeister) with Copilot wants to merge 14 commits into
mainfrom
copilot/fix-auto-correct-aliases
Draft

Christoph Bergmeister (bergmeister) with Copilot wants to merge 14 commits into
mainfrom
copilot/fix-auto-correct-aliases

Conversation

Copilot AI commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Alias correction can rewrite DSC resource declarations such as Package PackageExample to Get-Package PackageExample, invalidating the configuration.

  • Resource detection: Exclude resource-shaped declarations inside configurations from implicit Get- prefix correction, supporting opening braces on either line.
  • Command handling: Preserve correction of explicit aliases and executable commands inside functions and DSC script properties.
  • Regression coverage: Cover both brace layouts and distinguish resource declarations from ordinary commands.

The following declaration should remain unchanged:

Configuration PackageTest {
    Package PackageExample
    {
        Name = 'TestPackage'
    }
}

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix auto correct aliases for DSC resources Preserve DSC resource names during alias correction Oct 27, 2026

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.

🟡 Changes recommended

The shared guard suppresses expected Get- corrections for executable commands in configurations and adds quadratic sibling-statement searches even in ordinary scripts.

3 open issues
What changed in this PR

This PR updates alias correction to distinguish DSC resource declarations from executable commands, addressing resource names such as Package being incorrectly rewritten as Get-Package.

Changes:

  • Adds resource detection for opening braces on the same or following line.
  • Adds context checks intended to preserve corrections inside executable code.
  • Adds regression tests for resource formatting, explicit aliases, and ordinary commands.
File Description
Tests/​Rules/​AvoidUsingAlias.tests.ps1 Adds formatting and command-analysis regression coverage.
Rules/​AvoidAlias.cs Adds DSC resource detection before implicit Get- prefix correction.

Review effort: Balanced

Comment thread Rules/AvoidAlias.cs Outdated
Comment thread Rules/AvoidAlias.cs
Comment thread Rules/AvoidAlias.cs Outdated
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
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.

Comment thread Rules/AvoidAlias.cs Outdated
Comment thread Rules/AvoidAlias.cs Outdated
Comment thread Rules/AvoidAlias.cs
Comment thread Rules/AvoidAlias.cs Outdated

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.

🟡 Changes recommended

PowerShell 7 background pipelines are misclassified as resource declarations in fallback configuration ASTs, suppressing expected alias corrections in two layouts lacking regression coverage.

2 open issues

Review effort: Balanced

Comment thread Rules/AvoidAlias.cs
Comment thread Rules/AvoidAlias.cs
* Initial plan

* Reject background pipelines as DSC resources

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>

* Guard background AST API for CoreCLR

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>

* Make background pipeline test expectations version-aware

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
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.

🔵 Needs a closer look

Human assessment is needed because the following-line AST path can misclassify an executable cmdlet as configuration syntax and suppress an expected Get-Verb diagnostic.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

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.

🟡 Changes recommended

The fallback AST handling can misclassify an executable command followed by a standalone block as a resource, suppressing a valid Get-Verb diagnostic; it needs the same alias and command-resolution checks as the same-line path, preserving the Node exception, plus a regression test.

1 open issue

Review effort: Balanced

Comment thread Rules/AvoidAlias.cs Outdated
* Initial plan

* Guard following-line DSC resource detection

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
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.

🔵 Needs a closer look

Human assessment is needed because separate-runspace command resolution can misclassify script-defined function callbacks as resource bodies, suppressing expected corrections.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

🟡 Changes recommended

The two-element exception in AvoidAlias.cs suppresses the Get-ChildItem correction for gci . followed by a next-line block, making alias handling inconsistent with same-line brace placement.

1 open issue

Review effort: Balanced

Comment thread Rules/AvoidAlias.cs Outdated
* Initial plan

* Fix AvoidAlias DSC regression

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>

* Fix Windows Pester expected alias count

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
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.

Auto Correct Aliases incorrectly expands DSC resources name thinking its an alias of a cmdlet

3 participants