Ternary operator gets formatted to Where-Object
See original GitHub issuePrerequisites
- 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
ms-vscode.powershell@2022.5.1
Steps to Reproduce
- Save a powershell script with content:
1 -eq 2 ? 1 : 2
-
Run the vscode format document (Ctrl+K Ctrl+D)
-
The output should be
1 -eq 2 Where-Object 1 : 2
Visuals
Logs
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Ternary operator in PowerShell
It's a conditional operator or ternary if. It's not "the ternary operator" since all that means is a operator (any operator) that takes...
Read more >PowerShell 7 – Ternary Operator - blog.ukotic.net
This operator can be used in place of conditional statements If and Else. The ternary operator follows the format of the C# language...
Read more >about Operators - PowerShell
Use arithmetic operators ( + , - , * , / , % ) to calculate values in a command or expression. With...
Read more >Untitled
PR has a meaningful title molmassa ticl4 Ternary operator gets formatted to Where-Object #1791 - GitHub about Operators - PowerShell Microsoft Learn Add ......
Read more >How I Format The Conditional Ternary Operator In ...
Ben Nadel shares his code formatting approach to the Conditional Ternary Operator in languages like ColdFusion and JavaScript.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks to me like this is yet-to-be-supported in PSScriptAnalyzer, https://github.com/PowerShell/PSScriptAnalyzer/issues/1314
You are correct @gogbg, more info here: https://github.com/PowerShell/vscode-powershell/issues/3978 So sorry, we took a community PR and did not realize it was a breaking change.