PowerShell / PowerShell/PSScriptAnalyzer

PSUseConsistentWhitespace for Pester tests and 'Should Throw'

オープン
#1,298 コメント 5 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Area - Formatter
主要言語
C#
スター
2.2k
フォーク
414
平均マージ
13時間 1分
マージ済み PR(30日)
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.

image

{
	"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

Various configuration files.zip

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. 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

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。