PowerShell / PowerShell/PSScriptAnalyzer

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

未关闭
#2,025 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Issue-Bug
主要语言
C#
星标
2.2k
派生
414
平均合并
13 小时 1 分钟
30 天内合并 PR
2

描述

Prerequisites
  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.
Summary

When using the powershell formatter to format a DSC script, it incorrectly expands DSC resource e.g Package gets expanded to Get-Package which is incorrect in context of DSC.

PowerShell Version
Name                           Value
----                           -----
PSVersion                      7.4.3
PSEdition                      Core
GitCommitId                    7.4.3
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : ConsoleHost
Version          : 7.4.3
InstanceId       : 18115bb7-f7da-45d7-bb4b-e3714de77d09
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace
Visual Studio Code Version
1.91.0
ea1445cc7016315d0f5728f8e8b12a45dc0a7286
arm64
Extension Version
ms-vscode.powershell@2024.2.2
Steps to Reproduce
  • Add below snippet to VSCode with "powershell.codeFormatting.autoCorrectAliases": true set.
  • Make sure VSCode detects the langugae as Poweshell or manually set it, then run formatter using Alt+Shift+F

Code Snippet

Configuration PackageTest
{
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'

Package PackageExample
    {
        Ensure = "Present"
        Path = "$Env:SystemDrive\TestFolder\TestProject.msi"
        Name = "TestPackage"
        ProductId = "ACDDCDAF-80C6-41E6-A1B9-8ABD8A05027E"
    }
}

Expected behavior

Configuration PackageTest {
  Import-DscResource -ModuleName 'PSDesiredStateConfiguration'

  Package PackageExample
  {
    Ensure = 'Present'
    Path = "$Env:SystemDrive\TestFolder\TestProject.msi"
    Name = 'TestPackage'
    ProductId = 'ACDDCDAF-80C6-41E6-A1B9-8ABD8A05027E'
  }
}

Actual behavior

Configuration PackageTest {
  Import-DscResource -ModuleName 'PSDesiredStateConfiguration'

  Get-Package PackageExample
  {
    Ensure = 'Present'
    Path = "$Env:SystemDrive\TestFolder\TestProject.msi"
    Name = 'TestPackage'
    ProductId = 'ACDDCDAF-80C6-41E6-A1B9-8ABD8A05027E'
  }
}
Visuals

No response

Logs

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先定位处理 powershell.codeFormatting.autoCorrectAliases 设置的 formatter 路径,然后使用提供的 DSC Package 配置重现该问题。验证 formatter 如何区分 cmdlet 别名和 DSC 资源名称,并确认格式化会保留 Package,同时仍会更正适用的别名。

由索引模型根据 Issue 内容生成。

评估

技术栈
powershell
领域
tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。