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

"Format Document" removes stream redirection operators when "powershell.codeFormatting.whitespaceBetweenParameters": true, changing semantics of code #5019

Closed
4 of 6 tasks
mmotejlek opened this issue Jul 27, 2024 · 1 comment
Labels
Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed!

Comments

@mmotejlek
Copy link

mmotejlek commented Jul 27, 2024

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

After using the "Format Document" command when "powershell.codeFormatting.whitespaceBetweenParameters": true is set, stream redirection operators like 2>&1 from statements like Get-Content "a.txt" 2>&1 > "b.txt" are removed, resulting in Get-Content "a.txt" > "b.txt", which changes what the code does. That should not happen after autoformatting code.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.4.3
PSEdition                      Core
GitCommitId                    7.4.3
OS                             Microsoft Windows 10.0.19045
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       : a13ae448-bd0c-4cd1-9d1b-e524f257013e
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : cs-CZ
CurrentUICulture : cs-CZ
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

1.91.1
f1e16e1e6214d7c44d078b1f0607b2388f29d729
x64

Extension Version

Steps to Reproduce

  1. Set in VSCode JSON settings:
"powershell.codeFormatting.whitespaceBetweenParameters": true
  1. Create new .ps1 file
  2. Write
Get-Content "a.txt" 2>&1 > "b.txt"
  1. Run "Format Document" VSCode command (Shift+Alt+F)
  2. Result is:
Get-Content "a.txt" > "b.txt"

Visuals

No response

Logs

No response

@mmotejlek mmotejlek added Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed! labels Jul 27, 2024
@andyleejordan
Copy link
Member

Hi, this is/was a bug in PSScriptAnalyzer: PowerShell/PSScriptAnalyzer#2000 the fix has been merged but we're still pending a release (which we'll then need to pull in here) so it'll be fixed soon enough!

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

2 participants