PowerShell / PowerShell/PSScriptAnalyzer
PSUseDeclaredVarsMoreThanAssignments is not aware of the scriptblock context (invocation or dot-sourcing)
Offen
Dieses Issue hat noch niemand übernommen.
Area - PSUseDeclaredVarsMoreThanAssignments
Area - Rules
- Vorherrschende Sprache
- C#
- Sterne
- 2.2k
- Forks
- 414
- Ø Merge
- 13 Std. 1 Min.
- Gemergte PRs (30 T.)
- 2
Beschreibung
Steps to reproduce
Extracted from here but similar issues also reported in #711
It’s a PSSA bug. I get the same warning with:
$totalSize = 0
. { $totalSize += 1 }
$totalSize
PSSA is apparently analyzing each script block independently.
It needs to recognize when a script block is dot sourced and analyze it in the context of where it is >invoked. This isn’t always possible, but it’s usually easy to do when using ForEach-Object (which dot >sources like this).
In trying some variants on the idea, it seems like there are multiple bugs:
$totalSize = 0
function foo {
$x = $totalSize + 1
$totalSize = $x # Should warn, doesn't (bug)
}
& {
$x = $totalSize + 1
$totalSize = $x # Should warn, doesn't (bug)
}
. {
$x = $totalSize + 1
$totalSize = $x # Should not warn, doesn't (no bug)
}
. {
$totalSize += 1 # Should not warn, does (bug)
}
$totalSize
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der Implementierung von PSUseDeclaredVarsMoreThanAssignments und reproduziere die im Issue aufgeführten Beispiele für Aufruf, Dot-Sourcing, Funktion und Scriptblock. Vergleiche jede Diagnose mit dem in den Kommentaren beschriebenen erwarteten Verhalten; abgeschlossen ist die Aufgabe, wenn der Analyzer diese Kontexte ohne False Positives oder fehlende Warnungen verarbeitet.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- csharp, powershell
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100