Unable to run rules with hashtable that run fine with settings file
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- powershell
- Área
- tooling
Línea de trabajo
Empieza ejecutando repro.ps1 con PSScriptAnalyzerSettings.psd1 en los entornos de PowerShell 7.4.6 y 5.1 indicados, y luego sigue cómo Invoke-ScriptAnalyzer gestiona la ruta del archivo frente a la hashtable de configuración importada. Se considera completado cuando la entrada ExcludeRules suprime PSUseDeclaredVarsMoreThanAssignments en ambas llamadas, con cobertura de regresión para el comportamiento diferente de PowerShell.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Steps to reproduce
This is essentially the opposite of #1160
The attached zip file concisely contains the repro:
PSScriptAnalyzerSettingsHashtableRepro.zip
But here it is in plain text too
# repro.ps1
Write-Output "Using settings file"
Invoke-ScriptAnalyzer -Path .\repro.ps1 -Settings '.\PSScriptAnalyzerSettings.psd1'
# Create an unused variable which triggers a warning that the settings file should suppress
$unusedVariable = 1
$settings = Import-PowerShellDataFile -Path '.\PSScriptAnalyzerSettings.psd1'
Write-Output "Loaded settings to hashtable:"
$settings | ConvertTo-Json | Write-Output
Write-Output "Using setting hashtable"
Invoke-ScriptAnalyzer -Path .\repro.ps1 -Settings $settings
# PSScriptAnalyzerSettings.psd1
@{
ExcludeRules = @(
'PSUseDeclaredVarsMoreThanAssignments'
)
}
Expected behavior
The warning should be suppressed in both calls to Invoke-ScriptAnalyzer. Output from the repro script should be this:
Using settings file
Loaded settings to hashtable:
{
"ExcludeRules": [
"PSUseDeclaredVarsMoreThanAssignments"
]
}
Using setting hashtable
Actual behavior
The warning is only suppressed in the first call (the one that references the file directly). The call that passes the settings hashtable does not suppress the error. Output from the repro script is this:
Using settings file
Loaded settings to hashtable:
{
"ExcludeRules": [
"PSUseDeclaredVarsMoreThanAssignments"
]
}
Using setting hashtable
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSUseDeclaredVarsMoreThanAssignment Warning repro.ps1 6 The variable 'unusedVariable' is assigned but never
s used.
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 7.4.6
PSEdition Core
GitCommitId 7.4.6
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
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.23.0
Note that this issue does NOT happen in this environment (i.e. the warning is suppressed in both calls):
> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.26100.2161
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.26100.2161
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
> (Get-Module -ListAvailable PSScriptAnalyzer).
Version | ForEach-Object { $_.ToString() }
1.23.0
It appears to be related to the Powershell version.
- Lenguaje dominante
- C#
- Estrellas
- 2.2k
- Forks
- 415
- Merge medio
- 13 h 1 min
- PR fusionados (30 d)
- 2
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de PowerShell/PSScriptAnalyzer
-
Up-for-Grabs
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
PowerShell/PSScriptAnalyzer#2213 · 2 comentarios ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
PowerShell/PSScriptAnalyzer#2217 · 1 comentario ·
-
PSUseConsistentIndentation double-indents attribute bodies that open a scriptblock (`[Attr({ … })]`) Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 70/100
PowerShell/PSScriptAnalyzer#2216 · 2 comentarios ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
PowerShell/PSScriptAnalyzer#2211 ·
-
`PSPlaceOpenBrace` and `PSPlaceCloseBrace` leave trailing whitespace when expanding one-line blocks Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 70/100
PowerShell/PSScriptAnalyzer#2210 ·
Todos los issues de PowerShell/PSScriptAnalyzer
Issues similares
-
Status: Waiting triage Type: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
nanoframework/Home#1857 ·
-
kind/bug kind/regression
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
unoplatform/uno.toolkit.ui#1646 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
nightscout/nocturne#1379 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
elastic/esql-dotnet#47 ·
-
port: add go-steam fork Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100