Skip to content

Code Formatting : Whitespacing one line hashtable #1113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
noupii opened this issue Dec 19, 2018 · 3 comments
Open

Code Formatting : Whitespacing one line hashtable #1113

noupii opened this issue Dec 19, 2018 · 3 comments

Comments

@noupii
Copy link

noupii commented Dec 19, 2018

Hello
I am looking for a improvment on the current formatting tools by adding a whitespace after open bracket and before closing non empty curly brackets like :

#Actual
$emptyHash = @{ }               # an empty Hash
$myHash = @{foo = "bar"}

#Expected
$emptyHash = @{}                # an empty Hash
$myHash = @{ foo = "bar" } #whitespace after `{ `and before ` }`

Additional information:

  • I use the PowerShell extension on VS Code to format automaticaly my code on save.

  • My settings.json file:

{
    "editor.formatOnSave": true,
    "powershell.codeFormatting.preset": "Custom",
    "powershell.codeFormatting.alignPropertyValuePairs": true,
    "powershell.codeFormatting.ignoreOneLineBlock": false,
    "powershell.codeFormatting.newLineAfterCloseBrace": true,
    "powershell.codeFormatting.newLineAfterOpenBrace": true,
    "powershell.codeFormatting.openBraceOnSameLine": false,
    "powershell.codeFormatting.whitespaceAfterSeparator": true,
    "powershell.codeFormatting.whitespaceAroundOperator": true,
    "powershell.codeFormatting.whitespaceBeforeOpenBrace": true,
    "powershell.codeFormatting.whitespaceBeforeOpenParen": true,
    "powershell.scriptAnalysis.enable": true,
    "files.trimTrailingWhitespace": true,
}

This feature exist on other language :
microsoft/TypeScript#9613 (comment)

Regards,

@bergmeister
Copy link
Collaborator

bergmeister commented Dec 19, 2018

@Joe-Tux You will be pleased that currently there is already the open PR #1092 that will take care of the whitespace inside curly braces and I'also double checked that it also includes hashtables as well.

@msftrncs
Copy link

msftrncs commented May 7, 2019

@bergmeister, it seems part of this issue has been addressed, but I am still seeing empty hashtable's being spaced out: @{} -> @{ }.

@daviesj
Copy link
Contributor

daviesj commented Sep 29, 2020

As of version 1.19.1 I am still seeing a problem here but it has changed. Now if you try the same example, this is what you get:

PS> Invoke-Formatter '$myHash = @{foo = "bar"}'
$myHash = @{foo = "bar" }

There is now a space added before the right brace but not after the left brace.

I have to say I disagree with the OP though. To me, a hashtable literal seems closer to an array literal than a script block, so if @(1, 2, 3) is valid formatting then why not @{foo = "bar"}? However, I realize that is a matter of opinion. Either @{foo = "bar"} or @{ foo = "bar" } is better than @{foo = "bar" } which is what you get now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants