Skip to content
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

Formatting breaks pattern needed for null-conditonal operators by adding spaces #5041

Open
6 tasks done
ThaDaVos opened this issue Sep 14, 2024 · 0 comments
Open
6 tasks done
Labels
Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed!

Comments

@ThaDaVos
Copy link

Prerequisites

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

I've been debugging my script for hours, and finally figured out that the format I did last time, broke my null-conditional operators as it adds spaces between the braces, for example:

$c = $a.{b}?.Trim();

Turns into

$c = $a.{ b }?.Trim();

Causing $c to be empty/null

I fixed this manually in my script but noticed that formatting changes it back - I think this is a wrong format for this specific use-case as it breaks these operators.

Information about the operator: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.4#null-conditional-operators--and-

PowerShell Version

PS> $PSVersionTable; $Host

Name                           Value
----                           -----
PSVersion                      7.4.5
PSEdition                      Core
GitCommitId                    7.4.5
OS                             Microsoft Windows 10.0.27695
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : Visual Studio Code Host
Version          : 2024.2.2
InstanceId       : 7973e8e2-cbb7-4e99-98e3-9169ba600aa3
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : nl-NL
CurrentUICulture : nl-NL
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

PS> code --version
1.93.1
38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40
x64

Extension Version

PS> code --list-extensions --show-versions | Select-String powershell

[email protected]

Steps to Reproduce

  1. Write code as follows:
$c = $a.{b}?.Trim();
  1. Use document format in vscode

Visuals

No response

Logs

No response

@ThaDaVos ThaDaVos added Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed! labels Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed!
Projects
None yet
Development

No branches or pull requests

1 participant