PowerShell / PowerShell/PSScriptAnalyzer
Suggestion for new rule - Ensure that variables used in a function is always declared in the local scope
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 2.2k
- Fork
- 414
- Merge medio
- 13h 1m
- PR unite (30g)
- 2
Descrizione
In order to reduce the number of hard to debug errors, we run our PowerShell scripts with Set-StrictMode -Version Latest. This lets us catch issues where we e.g. have misspelled a variable name (or forgot to assign it before using it) during runtime. But it would be immensely useful to catch these kinds of errors before we run the scripts, e.g. during an automated build.
We have deployment scripts that run for quite a long time (several hours), and silly misspelled variable names or misplaced variable assignments then costs quite a bit of development time. Catching these errors early would be immensely useful.
Example of something that should cause an error:
function Get-Foobar()
{
if ($b + 2 -gt 5)
{
return $b
}
return 5
}
This would be OK:
function Get-Foobar($b)
{
if ($b + 2 -gt 5)
{
return $b
}
return 5
}
As would this:
function Get-Foobar()
{
$b = 123;
if ($b + 2 -gt 5)
{
return $b
}
return 5
}
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 dai due esempi PowerShell presenti nell’issue ed esamina le regole e i test dell’analyzer già presenti nel repository per determinare dove inserire una nuova regola. Definisci come devono essere gestiti i parametri, le assegnazioni e i riferimenti alle variabili; il lavoro è completato quando l’esempio con la variabile non dichiarata viene segnalato, mentre entrambi gli esempi validi passano, con una copertura per il comportamento scelto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- powershell
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100