PowerShell / PowerShell/PSScriptAnalyzer

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

Abierto
#2,025 0 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Issue-Bug
Lenguaje dominante
C#
Estrellas
2.2k
Forks
414
Merge medio
13 h 1 min
PR fusionados (30 d)
2

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza localizando la ruta del formatter que gestiona la configuración powershell.codeFormatting.autoCorrectAliases y, a continuación, reproduce el problema con la configuración de DSC Package proporcionada. Verifica cómo distingue el formatter los alias de cmdlet de los nombres de recursos DSC y confirma que el formateo conserva Package y sigue corrigiendo los alias aplicables.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
powershell
Área
tooling
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.