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

Ternary operator gets formatted to Where-Object #1791

Closed
6 tasks done
gogbg opened this issue May 9, 2022 · 11 comments
Closed
6 tasks done

Ternary operator gets formatted to Where-Object #1791

gogbg opened this issue May 9, 2022 · 11 comments

Comments

@gogbg
Copy link

gogbg commented May 9, 2022

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.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

I'm experiencing issue with the format document functionality which is incorrectly modifying the ternary operator(?) in statements to 'Where-Object'.

PowerShell Version

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

Visual Studio Code Version

1.67.0
57fd6d0195bb9b9d1b49f6da5db789060795de47
x64

Extension Version

Steps to Reproduce

  1. Save a powershell script with content:
1 -eq 2 ? 1 : 2
  1. Run the vscode format document (Ctrl+K Ctrl+D)

  2. The output should be

1 -eq 2 Where-Object 1 : 2

Visuals

image

Logs

No response

@gogbg gogbg added the Issue-Bug label May 9, 2022
@ghost ghost added the Needs: Triage 🔍 label May 9, 2022
@VOVELEE
Copy link

VOVELEE commented May 9, 2022

I face the same issue. Please fix :)

@andyleejordan
Copy link
Member

Looks to me like this is yet-to-be-supported in PSScriptAnalyzer, #1314

@SydneyhSmith SydneyhSmith transferred this issue from PowerShell/vscode-powershell May 9, 2022
@SydneyhSmith
Copy link
Collaborator

Looks like this is also relate to #1362

Could you also please confirm the version of PSSA being run by calling gmo PSScriptAnalyzer in the integrated console?

@gogbg
Copy link
Author

gogbg commented May 12, 2022

@SydneyhSmith I don't have any version of PSScriptAnalyzer, but I believe the vscode powershell extension comes with specific version of the PSScriptAnalyzer included, in this case it's 1.20.0, which is executed "somewhere behind the scenes"

@bergmeister
Copy link
Collaborator

I can reproduce this issue only if I use Windows PowerShell to run something like Invoke-ScriptAnalyzer -Path C:\Users\c.bergmeister\git\test.ps1 -Fix. Therefore to me that indicated that the PowerShell Intergrated Console of the VS-Code extension is run using Windows PowerShell and not PowerShell Core. Can you please confirm this by running $PSVersionTable in it, you can pop up that integrated terminal with Ctrl+J.
If it's that then this is by design as Windows PowerShell will never be able to understand the new syntax as PSSA relies on PowerShell's parser. One thing I did point out previously though is that the extension should not apply corrections if there are DiagnosticRecord objects of Severity ParseError @andschwa as we had other issues as well where wrong corrections were being applied because PowerShell's parsers tries a best efforts, see e.g. #1571

@gogbg
Copy link
Author

gogbg commented May 20, 2022

Seems like the latest vscode powershell extension version comes with a breaking change to the setting "powershell.powerShellAdditionalExePaths". It is no longer array but an object, once I adjusted this setting this bug is no longer observable.

Previously it was:

  "powershell.powerShellAdditionalExePaths": [
    {
      "versionName":"PowerShell 7.2.4",
      "exePath":"C:\\ProgramData\\PowerShell\\7.2.4\\pwsh.exe"
    }
  ]

Now(the working setting for [email protected]) is:

  "powershell.powerShellAdditionalExePaths": {
    "PowerShell 7.2.4": "C:\\ProgramData\\PowerShell\\7.2.4\\pwsh.exe"
  },

@gogbg gogbg closed this as completed May 20, 2022
@andyleejordan
Copy link
Member

You are correct @gogbg, more info here: PowerShell/vscode-powershell#3978 So sorry, we took a community PR and did not realize it was a breaking change.

@lzandman
Copy link

lzandman commented Jul 1, 2024

It seems this issue is still unsolved. It just happened in my editor. I don't get why it was closed. @gogbg

@gogbg
Copy link
Author

gogbg commented Jul 9, 2024

@lzandman check your vscode config, as I described here #1791 (comment)

@lzandman
Copy link

lzandman commented Jul 9, 2024

@lzandman check your vscode config, as I described here #1791 (comment)

But that is a response from 2022. It looks like a quick workaround/hack to make things work. Does this mean the underlying issue hasn't actually been resolved and this bug is still present in VSCode?

@gogbg
Copy link
Author

gogbg commented Jul 10, 2024

@lzandman the issue resolved for me when I adjusted the VSCode PowerShell extension version to PowerShell 7.2.4.

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

6 participants