Skip to content

codeFormatting.IgnoreOneLineBlock / hashtable problem #1284

@itfranck

Description

@itfranck

Code formatting does not behave properly when declaring a hashtable in a IF condition.

Steps to reproduce

Set your codeFormatting options in vscode to:

"powershell.codeFormatting.ignoreOneLineBlock": true,
"powershell.codeFormatting.openBraceOnSameLine": true,
"powershell.codeFormatting.newLineAfterCloseBrace": true,
"powershell.codeFormatting.newLineAfterOpenBrace": true,

Write the following statement

  if ($test -eq $null) {$test = @{}}
    if ($test -eq $null) {
        $test = @{ }
    }

Expected behavior

This is actually what happens when $test is an array and what you should expect from an hashtable assignment.

if ($test -eq $null) { $test = @() }
if ($test -eq $null) {
    $test = @()
}

Actual behavior

This is what actually happens with hashtables.

   if ($test -eq $null) { $test = @{ } 
    }
    if ($test -eq $null) {
        $test = @{ }
    }

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17763.503
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.503
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.18.0
(This is the version that comes with the latest versions of VSCode, from which this is used)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions