Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Enabling `powershell.codeFormatting.whitespaceBetweenParameters` and `powershell.codeFormatting.alignPropertyValuePairs` makes one of them always show a warning for Hashtable assignments

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
powershell, typescript
領域
devtools

調査の方向性

powershell.codeFormatting.whitespaceBetweenParameters と powershell.codeFormatting.alignPropertyValuePairs を有効にした状態で、issue にある複数行の hashtable の例を使って警告を再現します。まず、拡張機能が PSScriptAnalyzer の PSAlightAssignmentStatement CheckHashtable オプションと PSUseConsistentWhitespace IgnoreAssignmentOperatorInsideHashTable オプションをどのように処理しているかを追跡します。両方の設定を有効にしたとき、演算子の後に 1 つのスペースを置いた整列済みの hashtable 代入で、競合する警告が発生しなければ完了です。

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

説明

Issue-Bug Needs: Triage
Prerequisites
  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.
Summary

When having both powershell.codeFormatting.whitespaceBetweenParameters and powershell.codeFormatting.alignPropertyValuePairs enabled in the extension settings, the editor UI will always show the warning for one or the other. So multi-line hashtable assignments always have a yellow warning line under all of the key-value pairs, except the one that has the longest key-string.

In PSScriptAnalyzer, there is an option in the arguments for each of the two rules:
for PSAlightAssignmentStatement, there's CheckHashtable
for PSUseConsistentWhitespace there's IgnoreAssignmentOperatorInsideHashTable

If both of these respective options are enabled, the hashtable assignments receive no warnings when the = operators are aligned and there's only 1 space after.

The PowerShell VSCode extension should either detect when the two settings are enabled and enable the respective arguments automatically or offer the option to enable or disable the respective arguments if the settings are enabled so that multi-line hashtable assignments don't always receive warnings.

PowerShell Version
Name                           Value
----                           -----
PSVersion                      7.6.6
PSEdition                      Core
GitCommitId                    7.6.6
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : ConsoleHost
Version          : 7.6.6
InstanceId       : d8f39d3e-72c7-47bd-87fd-71c8a5f05138
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace
Visual Studio Code Version
1.137.0
645f29cc3176500b4b5762ba887cf2a7f0ffdf2c
x64
Extension Version
[email protected]
Steps to Reproduce

In VSCode Settings, enable both powershell.codeFormatting.whitespaceBetweenParameters and powershell.codeFormatting.alignPropertyValuePairs, then create a simple hashtable with multiple key-value pairs that have different legths of key-strings.

With Alignment:

$myHashtable = @{
    KeyOne   = 'item' # <- Warning: Use space before and after binary and assignment operators.
    Key2     = $aVariable # <- Warning: Use space before and after binary and assignment operators.
    KeyThree = 'ThirdValue' # <- No warning
    KeyFour  = $otherVariable # <- Warning: Use space before and after binary and assignment operators.
}
return @{
    Item1     = $false # <- Warning: Use space before and after binary and assignment operators.
    ItemTwo   = 2 # <- Warning: Use space before and after binary and assignment operators.
    ItemThree = $true # <- No warning
}

Without Alignment:

$myHashtable = @{
    KeyOne = 'item' # <- Warning: Assignment statements are not aligned.
    Key2 = $aVariable # <- Warning: Assignment statements are not aligned.
    KeyThree = 'ThirdValue' # <- No warning
    KeyFour = $otherVariable # <- Warning: Assignment statements are not aligned.
}
$myHashtable
return @{
    Item1 = $false # <- Warning: Assignment statements are not aligned.
    ItemTwo = 2 # <- Warning: Assignment statements are not aligned.
    ItemThree = $true # <- No warning
}
Visuals
Image Image
Logs

No response

主要言語
TypeScript
スター
1.9k
フォーク
549
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

PowerShell/vscode-powershell のほかの issue

PowerShell/vscode-powershell の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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