PowerShell / PowerShell/PSScriptAnalyzer
AvoidGlobalVars should only trigger on assignment
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- C#
- Estrelas
- 2.2k
- Forks
- 415
- Merge médio
- 13h 1min
- PRs com merge (30d)
- 2
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece localizando a regra PS AvoidGlobalVars e reproduza o exemplo de classe do PowerShell presente na issue no PowerShell 7.6-preview4. O fix estará concluído quando a leitura de $global:PSEdition não produzir nenhum aviso, enquanto atribuir uma variável ao escopo global continuar acionando a regra.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- powershell
- Domínio
- tooling
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 35/100