PowerShell / PowerShell/PSScriptAnalyzer
unary not is fooling tracker of variable use when assignment is in foreach loop
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 2.2k
- Fork
- 415
- Merge medio
- 13h 1m
- PR unite (30g)
- 2
Descrizione
Steps to reproduce
Get-AzAutomationSchedule $resourceGroup $automationAccount | ForEach-Object {
$PrimaryExists = $true
}
if (-not $PrimaryExists) {
Write-Output "hello"
}
Expected behavior
$PrimaryExists should not be flagged as assigned but never used.
Actual behavior
It is flagged.
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.2.3
PSEdition Core
GitCommitId 6.2.3
OS Linux 4.15.0-1056-oem #65-Ubuntu SMP Thu Sep 12…
Platform Unix
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.18.3
Notes
I tried to create a more concise example, but the assignment needs to be a foreach { } at the end of a pipeline to exhibit the error.
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.
Direzione di ricerca
Inizia eseguendo la pipeline PowerShell fornita e controllando la diagnostica dell'analizzatore per l'assegnazione all'interno del blocco ForEach-Object finale. Segui l'analisi dell'uso delle variabili che produce l'avviso assigned-but-unused, quindi aggiungi un test di regressione per questo esempio e conferma che l'avviso non venga più segnalato, mentre le normali assegnazioni inutilizzate continuino a essere segnalate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- powershell
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100