PowerShell / PowerShell/PSScriptAnalyzer
PSUseDeclaredVarsMoreThanAssignments is not aware of Pester's scoping
Aberta
Ninguém assumiu esta issue ainda.
Area - PSUseDeclaredVarsMoreThanAssignments
Area - Rules
Issue - Enhancement
- Linguagem predominante
- C#
- Estrelas
- 2.2k
- Forks
- 415
- Merge médio
- 13h 1min
- PRs com merge (30d)
- 2
Descrição
Steps to reproduce
Supposing a Pester Test file like below:
$here = $PsScriptRoot
Describe 'My Module' {
BeforeAll { $module = Import-Module "$here\MyModule.psd1" }
AfterAll { $module | Remove-Module -Force }
It 'can be loaded' {
$module | Should Not Be $null
}
}
Expected behavior
No warning on the $module variable, as it is used in the code below.
Actual behavior
Invoke-ScriptAnalyzer reports the following:
PSUseDeclaredVarsMoreThanAssignments Warning My.Tests.ps1 5 The variable 'module' is assigned but never used.
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.16299.251
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.16299.251
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.16.1
1.16.0
1.15.0
1.14.1
1.14.0
1.13.0
1.12.0
1.11.1
1.11.0
1.10.0
1.9.0
1.8.1
1.8.0
1.7.0
1.6.0
1.5.0
1.4.0
1.3.0
1.2.0
1.1.1
1.1.0
1.0.2
1.0.1
1.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 reproduzindo o exemplo do Pester e inspecione a regra PSUseDeclaredVarsMoreThanAssignments, concentrando-se em como ela rastreia as variáveis entre os blocos BeforeAll, AfterAll e It. O trabalho estará concluído quando o exemplo não relatar mais $module como atribuída, mas não utilizada, enquanto a regra continuar identificando atribuições genuinamente não utilizadas.
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