`PSPlaceOpenBrace` and `PSPlaceCloseBrace` leave trailing whitespace when expanding one-line blocks
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 70/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- powershell
- Bereich
- tooling
Rechercherichtung
Beginne damit, den einzeiligen Block über Invoke-Formatter nachzustellen, wobei PSPlaceOpenBrace und PSPlaceCloseBrace aktiviert und IgnoreOneLineBlock auf false gesetzt sind. Verfolge, wie diese Regeln den Block erweitern, und prüfe die zugehörigen Formatter-Tests; als erledigt gilt die Aufgabe, wenn die erwartete mehrzeilige Ausgabe kein nachgestelltes Leerzeichen nach break enthält, ohne PSAvoidTrailingWhitespace zu erfordern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- C#
- Sterne
- 2.2k
- Forks
- 415
- Ø Merge
- 13 Std. 1 Min.
- Gemergte PRs (30 T.)
- 2
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus PowerShell/PSScriptAnalyzer
-
Up-for-Grabs
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 78/100
PowerShell/PSScriptAnalyzer#2213 · 2 Kommentare ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
PowerShell/PSScriptAnalyzer#2217 · 1 Kommentar ·
-
PSUseConsistentIndentation double-indents attribute bodies that open a scriptblock (`[Attr({ … })]`) Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 70/100
PowerShell/PSScriptAnalyzer#2216 · 2 Kommentare ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
PowerShell/PSScriptAnalyzer#2211 ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
PowerShell/PSScriptAnalyzer#2209 ·
Alle Issues in PowerShell/PSScriptAnalyzer
Ähnliche Issues
-
type/automation type/tech-debt
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
t/bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
ci-failure-cause test-failure
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
area:auth FE mvp P3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
klasolsson81/jobbliggaren#1788 ·