PowerShell / PowerShell/vscode-powershell

Formatting an It block with unbalanced spacing causes issues

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

@andyleejordan がすでに取り組んでいます。

2022年6月6日 から。

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

説明

Prerequisites
  • I have written a descriptive issue title.
  • I have searched all 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

With the code (note two spaces between ) and { on line 7):

It "should create applications in Intune (<_>)" -ForEach @(
    $Packages
    @{
        Name  = 'installpackage'
        Version = '1.0.0'
    }
)  {
    $Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}

When selecting to Format Document, results in:

It
$Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}

When updating the code to include two spaces between -ForEach and @(:

It "should create applications in Intune (<_>)" -ForEach  @(
    $Packages
    @{
        Name  = 'installpackage'
        Version = '1.0.0'
    }
)  {
    $Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}

It correctly formats:

It "should create applications in Intune (<_>)" -ForEach @(
    $Packages
    @{
        Name    = 'installpackage'
        Version = '1.0.0'
    }
) {
    $Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}

And here's where it gets weird... When changing to three or more spaces on line 7:

It "should create applications in Intune (<_>)" -ForEach @(
    $Packages
    @{
        Name  = 'installpackage'
        Version = '1.0.0'
    }
)   {
    $Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}

It does not format at all. Until... there are 2 or more spaces between -ForEach and @{, then it formats correctly.

Compounding the issue, if you remove the It, the formatting works correctly.

"should create applications in Intune (<_>)" -ForEach @(
    $Packages
    @{
        Name  = 'installpackage'
        Version = '1.0.0'
    }
)  {
    $Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}

Formats to:

"should create applications in Intune (<_>)" -ForEach @(
    $Packages
    @{
        Name    = 'installpackage'
        Version = '1.0.0'
    }
) {
    $Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}

Finally: When run through Invoke-Formatter in the integrated terminal, formatting occurs as expected:

PS /Users/coryknox/git/chocolatey/ctk/16_engtasks_1510> Invoke-Formatter @'
>> It "should create applications in Intune (<_>)" -ForEach @(
>>     $Packages
>>     @{
>>         Name  = 'installpackage'
>>         Version = '1.0.0'
>>     }
>> )  {
>>     $Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
>> }
>> '@
It "should create applications in Intune (<_>)" -ForEach @(
    $Packages
    @{
        Name    = 'installpackage'
        Version = '1.0.0'
    }
) {
    $Output.Lines | Should -Contain "Application created in Intune: $_ ($" -Because $Output.String
}
PowerShell Version
Name                           Value
----                           -----
PSVersion                      7.2.3
PSEdition                      Core
GitCommitId                    7.2.3
OS                             Darwin 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Visual Studio Code Version
1.67.0-insider
ed2619e11b68bec43b788486230b0c2afeb4672d
x64
Extension Version
ms-vscode.powershell@2021.12.0
ms-vscode.powershell-preview@2022.4.3
TylerLeonhardt.vscode-inline-values-powershell@0.0.5
Steps to Reproduce

See Summary above

Visuals

https://user-images.githubusercontent.com/30301021/166330615-e23be282-6aae-4f80-9384-76535ac081f1.mp4

Logs

No response

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

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

はじめの一歩

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

評価

この issue はまだ評価されていません。

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

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