Repository navigation
Preserve DSC resource names during alias correction - #2270
Christoph Bergmeister (bergmeister) with Copilot wants to merge 14 commits into
Conversation
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
There was a problem hiding this comment.
🟡 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
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>
There was a problem hiding this comment.
🟡 Changes recommended
DSC resource detection incorrectly suppresses alias diagnostics for executable commands and pipeline elements, while introducing quadratic scanning for ordinary scripts.
7 open issues
This scans sibling statements before checking whether the command belongs to a configuration. For… · New Inside a configuration, executable commands such as$result = Verb Argument {}, `$action = { Verb… · New TheCommandExpressionAstexception accepts standalone blocks without checking that they belong to… · New The resource-body checks also accept commands belonging to a multi-command pipeline. For example,… · New Restrict resource command detection to standalone single-command pipelines Avoid correcting commands in directly assigned script blocks Defer DSC body lookup to prevent quadratic scans in ordinary scripts
Review effort: Balanced
* 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>
There was a problem hiding this comment.
🔵 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
There was a problem hiding this comment.
🟡 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
* 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>
There was a problem hiding this comment.
🔵 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
There was a problem hiding this comment.
🟡 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
* 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>

Alias correction can rewrite DSC resource declarations such as
Package PackageExampletoGet-Package PackageExample, invalidating the configuration.Get-prefix correction, supporting opening braces on either line.The following declaration should remain unchanged: