PowerShell / PowerShell/PSScriptAnalyzer
Settings file (.psd1) sometimes requires arrays even when specifying a single value
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 2.2k
- フォーク
- 414
- 平均マージ
- 13時間 1分
- マージ済み PR(30日)
- 2
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、PSAvoidUsingCmdletAliases と Whitelist = '%' を使用して、issue #1366 に記載された Pester テストを再現します。test.psd1 の設定がどのように読み取られ、Whitelist がどのように適用されるかを追跡します。スカラー値によってエイリアス警告が抑制され、回帰テストにパスすれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- powershell
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100