PowerShell / PowerShell/PSScriptAnalyzer
AvoidGlobalVars should only trigger on assignment
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 2.2k
- Fork
- 414
- Merge medio
- 13h 1m
- PR unite (30g)
- 2
Descrizione
PowerShell classes requires variables to be initialized in a method before reference. This causes issues with global variables without scoping as the parser will throw a Variable is not assigned in the method error. To get around this the variable must be scoped but this causes PSScriptAnalyzer to throw a violation. The rule should only trigger when assigning a variable to the global scope not reading.
Steps to reproduce
class Test {
[void] Abc() {
if ($global:PSEdition -eq 'core') { write-host core }
}
}
Expected behavior
No warnings
Actual behavior
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSAvoidGlobalVars Warning 3 Found global variable 'global:PSEdition'.
If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *
Environment data
7.6-preview4
1.24.0
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 individuando la regola PS AvoidGlobalVars e riproduci l'esempio di classe PowerShell dell'issue su PowerShell 7.6-preview4. Il fix è completato quando la lettura di $global:PSEdition non produce alcun avviso, mentre l'assegnazione di una variabile all'ambito globale continua ad attivare la regola.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- powershell
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100