PowerShell / PowerShell/PSScriptAnalyzer

preferences file does not support $env: variables

Abierto
#2,126 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
C#
Estrellas
2.2k
Forks
414
Merge medio
13 h 1 min
PR fusionados (30 d)
2

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Reproduce el problema con PSScriptAnalyzerSettings.psd1 e Invoke-ScriptAnalyzer usando tanto un CustomRulePath simple como una expresión $env: o $PSScriptRoot. Traza cómo se analiza el archivo de configuración y cómo se resuelve CustomRulePath; se considera terminado cuando se aceptan valores de variables de entorno compatibles sin el error de validación de la tabla hash y el comando documentado funciona.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
powershell
Área
tooling
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.