PowerShell / PowerShell/PSScriptAnalyzer
preferences file does not support $env: variables
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
Expected behavior
# # PSScriptAnalyzerSettings.psd1
# @{
# CustomRulePath = "rules.psm1"
# }
Invoke-ScriptAnalyzer -Path .\test.ps1 -Settings ./PSScriptAnalyzerSettings.psd1
outputs: (correct)
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSAvoidInvokeSomething Warning test.ps1 1 The command 'Invoke-Something' should not be used. Please
use 'Invoke-SomethingElse' instead
Actual behavior
# # PSScriptAnalyzerSettings.psd1
# @{
# CustomRulePath = "$PSScriptRoot/rules.psm1"
# }
Invoke-ScriptAnalyzer -Path .\test.ps1 -Settings ./PSScriptAnalyzerSettings.psd1
Outputs:
Invoke-ScriptAnalyzer: Value in the settings hashtable should be a string or an array of strings: line 2 column 22 in file [...]\Powershell\PSScriptAnalyzerSettings.psd1
Reasoning
according to this article,
Module manifests are loaded in RestrictedLanguage mode and may use these additional variables:
$PSScriptRoot
$PSEdition
$EnabledExperimentalFeatures
Any environment variable, like $env:TEMP
relative file paths CustomRulePath for my environment
were resolving relative to the cwd instead of relative to the settings.file in neovim. the
./rules.psm1 and rules.psm1 were not resolving correctly.
~/.../Powershell/PSScriptAnalyzerSettings.psd1
where '~' expands to HOMEDIR does work
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 7.5.2
PSEdition Core
GitCommitId 7.5.2
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
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
Reproduza o problema com PSScriptAnalyzerSettings.psd1 e Invoke-ScriptAnalyzer usando tanto um CustomRulePath simples quanto uma expressão $env: ou $PSScriptRoot. Rastreie como o arquivo de configurações é analisado e como CustomRulePath é resolvido; considera-se concluído quando valores de variáveis de ambiente compatíveis são aceitos sem o erro de validação da tabela hash e o comando documentado funciona.
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
- 45/100