PowerShell / PowerShell/PSScriptAnalyzer
Analyzer for Type Reassignment in `foreach` Loop
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 2.2k
- Fork
- 414
- Merge medio
- 13h 1m
- PR unite (30g)
- 2
Descrizione
Summary of the new feature
Consider the following script:
if ($true) {
[String]$MyVar = "Blah"
}
[int[]]$MyInts = @(1,2,3)
foreach ($MyVar in $MyInts) {
Write-Host "This is my type [$($MyVar.GetType())]"
}
A naïve C# reading of the above PowerShell would assume that the above would print out:
This is my type [int]
This is my type [int]
This is my type [int]
However this is PowerShell and due to Scoping Rules this actually returns:
This is my type [string]
This is my type [string]
This is my type [string]
Proposed technical implementation details (optional)
This has already burned me once in production.
As far as I can tell there is not an existing analyzer to determine this.
It is unclear if it is even feasible to do this reliably.
What is the latest version of PSScriptAnalyzer at the point of writing
PS > Get-Module | Where-Object {$_.Name -eq 'PSScriptAnalyzer' }
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 1.19.1 PSScriptAnalyzer {Get-ScriptAnalyzerRule, Invoke-Formatter, Invoke…
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
Non viene indicato alcun file sorgente, test o punto di ingresso. Inizia esaminando le regole esistenti dell’analizzatore e le regole di ambito di PowerShell collegate, quindi determina se la riassegnazione di tipi nei cicli foreach può essere rilevata in modo affidabile. Il lavoro è completato quando è presente una diagnosi documentata dell’analizzatore con test che coprono il comportamento dell’esempio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp, powershell
- Ambito
- tooling
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100