PowerShell / PowerShell/PSScriptAnalyzer
`PSPlaceOpenBrace` and `PSPlaceCloseBrace` leave trailing whitespace when expanding one-line blocks
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 2.2k
- フォーク
- 414
- 平均マージ
- 13時間 1分
- マージ済み PR(30日)
- 2
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、PSPlaceOpenBrace と PSPlaceCloseBrace を有効にし、IgnoreOneLineBlock を false に設定した状態で、一行ブロックを Invoke-Formatter に通して再現する。そのルールがブロックをどのように展開するかを追跡し、関連する formatter テストを確認する。完了条件は、PSAvoidTrailingWhitespace を要求せずに、期待される複数行出力で break の後に末尾スペースがないこと。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- powershell
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 活発
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 70/100