Skip to content

Format Document inserts spaces between curly braces after point operator #1741

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

Closed
5 tasks done
Bummibaer opened this issue Nov 10, 2021 · 7 comments · Fixed by #1750
Closed
5 tasks done

Format Document inserts spaces between curly braces after point operator #1741

Bummibaer opened this issue Nov 10, 2021 · 7 comments · Fixed by #1750

Comments

@Bummibaer
Copy link

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.

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.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      5.1.19041.1237
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1237
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Visual Studio Code Version

1.61.2
6cba118ac49a1b88332f312a8f67186f7f3c1643
x64

Extension Version

Steps to Reproduce

see above

Visuals

No response

Logs

No response

@JustinGrote
Copy link

JustinGrote commented Nov 10, 2021

Do you have these settings configured?
image
image

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 andyleejordan transferred this issue from PowerShell/vscode-powershell Nov 10, 2021
@ghost ghost added the Needs: Triage 🔍 label Nov 10, 2021
@andyleejordan
Copy link
Member

Formatting is done via PSScriptAnalyzer, transferring issue...

@bergmeister
Copy link
Collaborator

Adding this to my list to triage and fix this week.

@andyleejordan
Copy link
Member

Thanks @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
Copy link
Collaborator

No worries and I agree. The other one that you probably think of, which is on my list as well is #1580

@jborean93
Copy link

jborean93 commented 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.$varWithPropertyNameAsValue will work instead as a workaround for this problem.

@bergmeister
Copy link
Collaborator

bergmeister commented Nov 22, 2021

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.

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

Successfully merging a pull request may close this issue.

5 participants