PowerShell / PowerShell/PSScriptAnalyzer
PSUseConsistentWhitespace for Pester tests and 'Should Throw'
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ả
Steps to reproduce
Testing.Tests.ps1 contains:
Describe -Name 'Test' -Fixture {
It -Name 'Test' -Test {
{1 / 0} | Should throw
}
}
Expected behavior
No PSScriptAnalyzer issues.
Actual behavior
PSScriptAnalyzer requires a space before the opening brace. The indentation puts eight spaces before the brace. Maybe it's to do with the fact that there is nothing before the opening brace. However, this is the recommended way of testing for exceptions in Pester.

{
"resource": "/<REMOVED>/Testing.Tests.ps1",
"owner": "_generated_diagnostic_collection_name_#0",
"code": "PSUseConsistentWhitespace",
"severity": 4,
"message": "Use space before open brace.",
"source": "PSScriptAnalyzer",
"startLineNumber": 5,
"startColumn": 9,
"endLineNumber": 5,
"endColumn": 10
}
Environment data
VS Code
Version: 1.36.1 (user setup)
Commit: 2213894ea0415ee8c85c5eea0d0ff81ecc191529
Date: 2019-07-08T22:59:35.033Z
Electron: 4.2.5
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.18362
Installed Extensions for VS Code
alefragnani.Bookmarks
Damien.autoit
eamodio.gitlens
ms-vscode.csharp
ms-vscode.powershell
ms-vscode.powershell-preview
streetsidesoftware.code-spell-checker
vscode-icons-team.vscode-icons
> $PSVersionTable
Name Value
---- -----
PSVersion 6.2.2
PSEdition Core
GitCommitId 6.2.2
OS Microsoft Windows 10.0.18362
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.18.1
1.18.0
1.18.0
Various Settings Files
settings.json
PSScriptAnalyzerSettings.psd1
CustomRule.psm1
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
Tái hiện chẩn đoán bằng đoạn mã PowerShell từ Testing.Tests.ps1 với PSScriptAnalyzer 1.18.1, đồng thời xem xét các tệp PSScriptAnalyzerSettings.psd1 và CustomRule.psm1 được cung cấp. Theo dõi cách xử lý PSUseConsistentWhitespace đối với scriptblock được truyền cho Should throw. Hoàn thành khi cú pháp ngoại lệ Pester được khuyến nghị không tạo ra chẩn đoán khoảng trắng sai, trong khi các kiểm tra khoảng trắng khác vẫn hoạt động nguyên vẹn.
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
- 45/100