PowerShell / PowerShell/PSScriptAnalyzer

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

Đang mở
#2,025 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Issue-Bug
Ngôn ngữ chính
C#
Star
2.2k
Fork
414
Merge trung bình
13 giờ 1 phút
Pull request đã merge (30 ngày)
2

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách xác định đường dẫn của formatter xử lý thiết lập powershell.codeFormatting.autoCorrectAliases, sau đó tái hiện sự cố bằng cấu hình DSC Package được cung cấp. Xác minh cách formatter phân biệt alias của cmdlet với tên tài nguyên DSC, và xác nhận rằng việc định dạng vẫn giữ nguyên Package đồng thời tiếp tục sửa các alias phù hợp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
powershell
Lĩnh vực
tooling
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.