PowerShell / PowerShell/PSScriptAnalyzer
Settings file (.psd1) sometimes requires arrays even when specifying a single value
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
Generally, in .psd1 files - and in PowerShell as a whole - it is fine to specify a scalar where an array is ultimately bound.
This is how it works in a module manifest's FunctionsToExport entry, for instance: instead of having to explicitly specify an array for a single entry - @('Get-Foo') or , 'Get-Foo - just 'Get-Foo' (scalar) is also accepted.
This is currently not the case in PSSA, at least for the PSAvoidUsingCmdletAliases rule's Whitelist property:
A scalar value is quietly ignored.
Not sure what other properties are affected.
Steps to reproduce
Run the following Pester test:
Describe "Scalar property-value test" {
BeforeAll {
Push-Location TestDrive:/
Import-Module -ErrorAction Stop PSScriptAnalyzer
}
It "Acceptes a scalar as a single value" {
@'
Rules = @{
Rules = @{
# Do not warn about using the '%' alias
# !! `@('%')` or `, '%'` are currently required - scalar '%' does NOT work.
PSAvoidUsingCmdletAliases = @{ Whitelist = '%' }
}
}
'@ > test.psd1
@'
1, 2 | % { $_ }
'@ > test.ps1
Invoke-ScriptAnalyzer -Settings test.psd1 test.ps1 | Should -BeNullOrEmpty
}
AfterAll {
Pop-Location
}
}
Expected behavior
The test should pass.
Actual behavior
The test fails, because a PSAvoidUsingCmdletAliases warning is still emitted, because the non-array value '%' didn't take effect.
Environment data
> $PSVersionTable
PowerShell Core v7.0.0-preview.5 (7.0.0-preview.5) on macOS 10.15.1
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.18.3
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comience reproduciendo la prueba de Pester descrita en issue #1366 con PSAvoidUsingCmdletAliases y Whitelist = '%'. Rastree cómo se leen las configuraciones de test.psd1 y cómo se aplica Whitelist; se considera terminado cuando el valor escalar suprime la advertencia de alias y la prueba de regresión pasa.
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
- 55/100