You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Format Document inserts spaces between curly braces after point operator #1741
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.
Summary
I have the following line: Add-Member -InputObject $computer -MemberType NoteProperty -Name LIRoom -Value $gld.{Custom.Büro}
After Format Document it looks: Add-Member -InputObject $computer -MemberType NoteProperty -Name LIRoom -Value $gld. { Custom.Büro }
which is syntactically false.
Thanks Christoph Bergmeister (@bergmeister)! My personal triage priority is any bug with destructive behavior (which has recently had some activity in the repo, but I can't find it right now).
While this does look like a bug I'm not sure using braces like this is actually what you want. AFAIK when you do a property accesor it will cast the value to a string so $obj.{My Property} will convert the scriptblock to a string and use that. It won't execute that script block so doing $obj."My Property" or even $obj.$varWithPropertyNameAsValue will work instead as a workaround for this problem.
Put it through the debugger, the OpenBrace part of PSUseConsistentWhitespace is causing this, a more minimal repro is $foo. { bar}. I am thinking we could fix this by checking whether the previous token is TokenKind.Dot and skip OpenBrace for such a brace. Opened PR below with a fix.
Activity
JustinGrote commentedon Nov 10, 2021
Do you have these settings configured?


It's a little odd you'd be using a scriptblock here vs. evaluating the scriptblock and assigning it here as a variable, this may be an edge case.
andyleejordan commentedon Nov 10, 2021
Formatting is done via PSScriptAnalyzer, transferring issue...
bergmeister commentedon Nov 10, 2021
Adding this to my list to triage and fix this week.
andyleejordan commentedon Nov 10, 2021
Thanks Christoph Bergmeister (@bergmeister)! My personal triage priority is any bug with destructive behavior (which has recently had some activity in the repo, but I can't find it right now).
bergmeister commentedon Nov 10, 2021
No worries and I agree. The other one that you probably think of, which is on my list as well is #1580
jborean93 commentedon Nov 11, 2021
While this does look like a bug I'm not sure using braces like this is actually what you want. AFAIK when you do a property accesor it will cast the value to a string so
$obj.{My Property}will convert the scriptblock to a string and use that. It won't execute that script block so doing$obj."My Property"or even$obj.$varWithPropertyNameAsValuewill work instead as a workaround for this problem.bergmeister commentedon Nov 22, 2021
Put it through the debugger, the
OpenBracepart ofPSUseConsistentWhitespaceis causing this, a more minimal repro is$foo. { bar}. I am thinking we could fix this by checking whether the previous token isTokenKind.Dotand skipOpenBracefor such a brace. Opened PR below with a fix.