Unable to run rules with hashtable that run fine with settings file
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- powershell
- Ambito
- tooling
Direzione di ricerca
Inizia eseguendo repro.ps1 con PSScriptAnalyzerSettings.psd1 negli ambienti PowerShell 7.4.6 e 5.1 indicati, quindi traccia il modo in cui Invoke-ScriptAnalyzer gestisce il percorso del file rispetto alla hashtable delle impostazioni importata. Il lavoro è completato quando la voce ExcludeRules sopprime PSUseDeclaredVarsMoreThanAssignments in entrambe le chiamate, con una copertura di regressione per il comportamento diverso di PowerShell.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C#
- Stelle
- 2.2k
- Fork
- 415
- Merge medio
- 13h 1m
- PR unite (30g)
- 2
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di PowerShell/PSScriptAnalyzer
-
Up-for-Grabs
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
PowerShell/PSScriptAnalyzer#2213 · 2 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
PowerShell/PSScriptAnalyzer#2217 · 1 commento ·
-
PSUseConsistentIndentation double-indents attribute bodies that open a scriptblock (`[Attr({ … })]`) Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 70/100
PowerShell/PSScriptAnalyzer#2216 · 2 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
PowerShell/PSScriptAnalyzer#2211 ·
-
`PSPlaceOpenBrace` and `PSPlaceCloseBrace` leave trailing whitespace when expanding one-line blocks Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 70/100
PowerShell/PSScriptAnalyzer#2210 ·
Tutte le issue di PowerShell/PSScriptAnalyzer
Issue simili
-
:watch: Not Triaged dotnet-fsharp/svc
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Client customer-reported needs-team-attention question Service Attention WebPubSub
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Azure/azure-sdk-for-net#63292 · 3 commenti · 1 reazione ·
-
Issue-Enhancement Needs-Triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
PowerShell/PowerShell#28061 · 2 reazioni ·
-
dependencies needs-team-triage server-Azure.Mcp
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
aspnet-core/svc aspnetcore-signalr/subsvc doc-enhancement Pri2 SignalR
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
dotnet/AspNetCore.Docs#37729 ·