From 74c856ed2ae9c9dc0b84e1f6bfb9973077b56bf1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Oct 2026 15:29:23 +0000 Subject: [PATCH 1/2] Initial plan From a9d141cada4e0f10e1434e2052f97a33a2b7c8ea Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 Oct 2026 15:35:14 +0000 Subject: [PATCH 2/2] Preserve DSC Node resource declarations Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> --- Rules/AvoidAlias.cs | 3 ++- Tests/Rules/AvoidUsingAlias.tests.ps1 | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Rules/AvoidAlias.cs b/Rules/AvoidAlias.cs index d59920db4..087e6bfc8 100644 --- a/Rules/AvoidAlias.cs +++ b/Rules/AvoidAlias.cs @@ -247,7 +247,8 @@ private bool IsDscResourceDeclaration(CommandAst cmdAst) { if (GetDscResourceBody(enclosingCommand) != scriptBlock || !String.IsNullOrEmpty(Helper.Instance.GetCmdletNameFromAlias(enclosingCommand.GetCommandName())) - || Helper.Instance.GetCommandInfo(enclosingCommand.GetCommandName()) != null) + || (!String.Equals(enclosingCommand.GetCommandName(), "Node", StringComparison.OrdinalIgnoreCase) + && Helper.Instance.GetCommandInfo(enclosingCommand.GetCommandName()) != null)) { return false; } diff --git a/Tests/Rules/AvoidUsingAlias.tests.ps1 b/Tests/Rules/AvoidUsingAlias.tests.ps1 index bae7310a7..2f2614a40 100644 --- a/Tests/Rules/AvoidUsingAlias.tests.ps1 +++ b/Tests/Rules/AvoidUsingAlias.tests.ps1 @@ -97,6 +97,22 @@ Configuration PackageTest { } Context "DSC resource ASTs" { + It "does not expand nested resource names in a same-line Node declaration when node is discoverable" -skip:(!(Get-Command node -CommandType Application -ErrorAction Ignore)) { + $target = @' +{ + Node localhost { Package PackageExample {} } +} +'@ + $ast = [System.Management.Automation.Language.Parser]::ParseInput($target, [ref]$null, [ref]$null) + $body = $ast.EndBlock.Statements[0].PipelineElements[0].Expression.Copy() + $configuration = [System.Management.Automation.Language.ConfigurationDefinitionAst]::new( + $ast.Extent, $body, 'Resource', + [System.Management.Automation.Language.StringConstantExpressionAst]::new($ast.Extent, 'Test', 'BareWord')) + $rule = [Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.AvoidAlias]::new() + + @($rule.AnalyzeScript($configuration, $null)).Count | Should -Be 0 + } + It "ignores resource declarations but not executable commands" { $target = @' {