question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ternary operator gets formatted to Where-Object

See original GitHub issue

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

ms-vscode.powershell@2022.5.1

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
andyleejordancommented, May 9, 2022

Looks to me like this is yet-to-be-supported in PSScriptAnalyzer, https://github.com/PowerShell/PSScriptAnalyzer/issues/1314

1reaction
andyleejordancommented, May 20, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found