PowerShell / PowerShell/PSScriptAnalyzer
Settings file (.psd1) sometimes requires arrays even when specifying a single value
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C#
- Star
- 2.2k
- Fork
- 414
- Merge trung bình
- 13 giờ 1 phút
- Pull request đã merge (30 ngày)
- 2
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện bài kiểm thử Pester được mô tả trong issue #1366 với PSAvoidUsingCmdletAliases và Whitelist = '%'. Theo dõi cách các thiết lập trong test.psd1 được đọc và cách Whitelist được áp dụng; hoàn tất khi giá trị vô hướng loại bỏ cảnh báo bí danh và bài kiểm thử hồi quy đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- powershell
- Lĩnh vực
- tooling
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 55/100