PowerShell / PowerShell/vscode-powershell

default settings for PSScriptAnalyzer are different to the CLI

Abierto
#5,385 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Area-Script Analysis Issue-Bug
Lenguaje dominante
TypeScript
Estrellas
1.9k
Forks
548
Métricas de merge de PR
Sin PR fusionados en 30 d

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

the default PSScriptAnalyzer config in the vscode extension seems to be different to the default config in the CLI

> Invoke-ScriptAnalyzer .\windows\foo.ps1

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSAvoidUsingWriteHost               Warning      foo.ps1    1     File 'foo.ps1' uses Write-Host. Avoid using Write-Host      
                                                                  because it might not work in all hosts, does not work when  
                                                                  there is no host, and (prior to PS 5.0) cannot be
                                                                  suppressed, captured, or redirected. Instead, use
                                                                  Write-Output, Write-Verbose, or Write-Information.

creating a PSScriptAnalyzerSettings.psd1 file and enabling the rule explicitly seems to fix it:

@{
    Severity=@('Error','Warning')
    IncludeRules=@('PSAvoidUsingWriteHost')
}

but i would rather not have to configure every single rule in order to have consistent behavior in the CLI and vscode

PowerShell Version
Name                           Value
----                           -----
PSVersion                      5.1.22621.6345
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.6345
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Name             : Visual Studio Code Host
Version          : 2025.4.0
InstanceId       : 4b4cb36f-0f98-4c1e-97e0-aaf3f2916128
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-AU
CurrentUICulture : en-GB
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace
Visual Studio Code Version
1.108.0
94e8ae2b28cb5cc932b86e1070569c4463565c37
x64
Extension Version
ms-vscode.powershell@2025.4.0
Steps to Reproduce
  1. install PSScriptAnalyzer: Install-Module -Name PSScriptAnalyzer -Force -scope currentuser
  2. create foo.ps1 with the following content:
    write-host asdf
    
  3. run Invoke-ScriptAnalyzer .\foo.ps1 and observe that the error is reported only in the CLI but not in vscode
Visuals
Image
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

Empieza rastreando la invocación de PSScriptAnalyzer de la extensión y compara sus valores predeterminados con el resultado informado de Invoke-ScriptAnalyzer .\foo.ps1. Reprodúcelo con un foo.ps1 que contenga write-host asdf. Se considera terminado cuando el mismo diagnóstico predeterminado aparece en VS Code sin un archivo PSScriptAnalyzerSettings.psd1.

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

Evaluación

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

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.