PowerShell / PowerShell/PSScriptAnalyzer
PSUseConsistentWhitespace for Pester tests and 'Should Throw'
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 2.2k
- 派生
- 414
- 平均合并
- 13 小时 1 分钟
- 30 天内合并 PR
- 2
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用 PSScriptAnalyzer 1.18.1,通过 Testing.Tests.ps1 中的 PowerShell 代码片段重现该诊断,并检查提供的 PSScriptAnalyzerSettings.psd1 和 CustomRule.psm1 文件。跟踪传递给 Should throw 的 scriptblock 的 PSUseConsistentWhitespace 处理过程。完成的标准是:推荐的 Pester 异常语法不会产生错误的空白诊断,同时其他空白检查保持不变。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- powershell
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100