PowerShell / PowerShell/PSScriptAnalyzer
PSUseConsistentWhitespace for Pester tests and 'Should Throw'
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- C#
- Estrellas
- 2.2k
- Forks
- 414
- Merge medio
- 13 h 1 min
- PR fusionados (30 d)
- 2
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Reproduzca el diagnóstico usando el fragmento de PowerShell de Testing.Tests.ps1 con PSScriptAnalyzer 1.18.1 y revise los archivos proporcionados PSScriptAnalyzerSettings.psd1 y CustomRule.psm1. Rastree el manejo de PSUseConsistentWhitespace para el bloque de script pasado a Should throw. Se considera terminado cuando la sintaxis de excepción recomendada de Pester no produce ningún diagnóstico falso de espacios en blanco, mientras las demás comprobaciones de espacios en blanco permanecen intactas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- powershell
- Área
- tooling
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100