PowerShell / PowerShell/PSScriptAnalyzer
`PSPlaceOpenBrace` and `PSPlaceCloseBrace` leave trailing whitespace when expanding one-line blocks
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
Format a one-line block with IgnoreOneLineBlock = $false:
Invoke-Formatter -ScriptDefinition "if (`$x) { BREAK }" -Settings @{
IncludeRules = @(
'PSPlaceOpenBrace'
'PSPlaceCloseBrace'
'PSUseConsistentIndentation'
'PSUseCorrectCasing'
)
Rules = @{
PSPlaceOpenBrace = @{
Enable = $true
OnSameLine = $true
NewLineAfter = $true
IgnoreOneLineBlock = $false
}
PSPlaceCloseBrace = @{
Enable = $true
NewLineAfter = $true
IgnoreOneLineBlock = $false
}
PSUseConsistentIndentation = @{ Enable = $true }
PSUseCorrectCasing = @{ Enable = $true }
}
}
Expected behavior
Expanding the block should not introduce trailing whitespace:
if ($x) {
break
}
Actual behavior
The output contains a trailing space after break. The ␠ below marks that space:
if ($x) {
break␠
}
The brace corrections replace only the brace tokens. The spaces that separated the one-line content from the braces survive as trailing whitespace after the block is expanded.
PowerShell/PSScriptAnalyzer#1992 and merged PowerShell/PSScriptAnalyzer#1993 are related, but not duplicates. They make PSAvoidTrailingWhitespace available to Invoke-Formatter when explicitly configured. They do not prevent PSPlaceOpenBrace and PSPlaceCloseBrace from introducing trailing whitespace. Callers should not need a separate cleanup rule to remove whitespace created by the formatter itself.
Environment data
Reproduced with:
- PSScriptAnalyzer 1.25.0 on PowerShell 7.5.2
- PSScriptAnalyzer built from
mainat PowerShell/PSScriptAnalyzer@4b0117ca7d2887711c9699f467ba7171f8859156 on PowerShell 7.6.4
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
Comienza reproduciendo el bloque de una sola línea mediante Invoke-Formatter, con PSPlaceOpenBrace y PSPlaceCloseBrace habilitados y IgnoreOneLineBlock establecido en false. Rastrea cómo esas reglas expanden el bloque e inspecciona las pruebas relacionadas del formateador; se considera terminado cuando la salida multilínea esperada no contiene un espacio final después de break sin requerir PSAvoidTrailingWhitespace.
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
- Activo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 70/100