PowerShell / PowerShell/PSScriptAnalyzer

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

オープン
#2,025 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Issue-Bug
主要言語
C#
スター
2.2k
フォーク
414
平均マージ
13時間 1分
マージ済み PR(30日)
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、powershell.codeFormatting.autoCorrectAliases 設定を処理する formatter のパスを特定し、提供された DSC Package 構成で問題を再現します。formatter が cmdlet のエイリアスと DSC リソース名をどのように区別しているかを確認し、フォーマットによって Package が維持される一方で、該当するエイリアスは引き続き修正されることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
powershell
領域
tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。