PowerShell / PowerShell/PSScriptAnalyzer

preferences file does not support $env: variables

Aberta
#2,126 0 comentários 0 reações 0 responsáveis Ver no GitHub

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

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. 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

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.