PowerShell / PowerShell/PSScriptAnalyzer

Formatting misses certain keywords (unary operators, 'until')

オープン
#2,095 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Area - Formatter Issue - Enhancement Up for Grabs
主要言語
C#
スター
2.2k
フォーク
414
平均マージ
13時間 1分
マージ済み PR(30日)
2

説明

I found that during formatting, some keywords aren't separated from leading braces (while), and some are seemingly ignored entirely (until). Also, unary operators (-not, -bnot, etc.) aren't separated with whitespace the same way as binary operators (-eq, -like, etc.).

Steps to reproduce

  1. Paste the following into a script
  2. Use Invoke-Formatter or the PowerShell VSCode extension to format the document
if(-not$false) {
    do{
        "Hello!"
    }until(
        $True
    )
    do{
        "Oh, hi!"
    }while(
        -not$True
    )
    while(-not$True) {
        "This won't show up."
    }
}

Expected behavior

Roughly the following output. Some is dependent on brace style (OTBS in this case), but all rules for inserting whitespace around keywords and operators should be enabled.

if (-not $false) {
    do {
        'Hello!'
    } until (
        $True
    )
    do {
        'Oh, hi!'
    } while (
        -not $True
    )
    while (-not $True) {
        "This won't show up."
    }
}

Actual behavior

if (-not$false) { # -not isn't separated by whitespace
    do {
        'Hello!'
    }until( # no whitespace around Until
        $True
    )
    do {
        'Oh, hi!'
    }while ( # only trailing whitespace for While
        -not$True # no separation
    )
    while (-not$True) { # no separation for -not and -bnot
        "This won't show up."
    }
}

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.19041.5737
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.5737
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.23.0

1.23.0 is the version included with the current (2025.0.0) VSCode PowerShell extension. I've also installed and tested 1.24.0 with the same results.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提供された reproducer を Invoke-Formatter で実行し、結果を期待される出力と比較します。formatter がキーワード while と until の間隔をどのように処理しているか、続いて -not や -bnot などの単項演算子をどのように処理しているかを追跡します。報告されたケースで示されているように、フォーマット済みの出力でこれらのキーワードと演算子が分離されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp, powershell
領域
tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。