PowerShell / PowerShell/PSScriptAnalyzer

PSUseConsistentWhitespace for Pester tests and 'Should Throw'

Aperta
#1,298 5 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Area - Formatter
Lingua principale
C#
Stelle
2.2k
Fork
414
Merge medio
13h 1m
PR unite (30g)
2

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riprodurre la diagnostica usando lo snippet PowerShell di Testing.Tests.ps1 con PSScriptAnalyzer 1.18.1 e riesaminare i file forniti PSScriptAnalyzerSettings.psd1 e CustomRule.psm1. Tracciare la gestione di PSUseConsistentWhitespace per lo scriptblock passato a Should throw. Il lavoro è completato quando la sintassi delle eccezioni Pester consigliata non produce alcuna falsa diagnostica relativa agli spazi bianchi, mentre gli altri controlli degli spazi bianchi rimangono intatti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
powershell
Ambito
tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.