Skip to content

Formatting settings miss certain tokens #5173

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

Closed
5 of 6 tasks
TMA-2 opened this issue Apr 14, 2025 · 3 comments
Closed
5 of 6 tasks

Formatting settings miss certain tokens #5173

TMA-2 opened this issue Apr 14, 2025 · 3 comments
Labels
Area-Script Analysis Issue-Bug A bug to squash. Pending: External This issue is not fixed here, it is fixed in a dependent repo such as PowerShell,PSScriptAnalyzer

Comments

@TMA-2
Copy link
Contributor

TMA-2 commented Apr 14, 2025

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

  • The setting ⚙ powershell.codeFormatting.whitespaceBeforeOpenParen doesn't add whitespace for the until keyword, but it does for while.
  • The setting ⚙ powershell.codeFormatting.whitespaceAroundOperator doesn't add whitespace around certain unary operators such as -not and -bnot, although it does for -join.
  • Both while and until keywords aren't separated from nearby braces the same way else, elseif, etc. are. This is regardless of the bracket preset: OTBS, Allman, etc.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      5.1.19041.5737
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.5737
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Name             : Visual Studio Code Host
Version          : 2025.0.0
InstanceId       : 78be6803-71c3-4ba5-9972-4fe334ca81df
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

1.99.0
4437686ffebaf200fa4a6e6e67f735f3edf24ada
x64

Extension Version

Steps to Reproduce

  1. Insert the following snippet into an editor
  2. Select and 'Format Selection', or 'Format Document'
if(-not(Get-Variable 'psEditor')) {
    do{
        Start-Sleep -Milliseconds 250
    }until(
        (Get-Variable 'psEditor')
    )
    do{
        Start-Sleep -Milliseconds 250
    }while(
        -not(Get-Variable 'psEditor')
    )
}

Visuals

The expected result would be something like...

if ( -not (Get-Variable 'psEditor')) {
    do {
        Start-Sleep -Milliseconds 250
    } until (
        (Get-Variable 'psEditor')
    )
    do {
        Start-Sleep -Milliseconds 250
    } while (
        -not (Get-Variable 'psEditor')
    )
}

However, the actual result is...

if (-not(Get-Variable 'psEditor')) { # No separation around -not
    do {
        Start-Sleep -Milliseconds 250
    }until( # No whitespace inserted here
        (Get-Variable 'psEditor')
    )
    do {
        Start-Sleep -Milliseconds 250
    }while ( # Whitespace inserted after, but not before keyword
        -not(Get-Variable 'psEditor') # No separation here
    )
}

Logs

No response

@TMA-2 TMA-2 added Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed! labels Apr 14, 2025
@JustinGrote
Copy link
Collaborator

Thanks for your submission!

All formatting is done by PSScriptAnalyzer, so please first confirm if you can reproduce this with invoke-scriptanalyzer.

@JustinGrote JustinGrote added Area-Script Analysis Needs: Author Feedback Please give us the requested feedback! and removed Needs: Triage Maintainer attention needed! labels Apr 15, 2025
@TMA-2
Copy link
Contributor Author

TMA-2 commented Apr 15, 2025

Thanks for your submission!

All formatting is done by PSScriptAnalyzer, so please first confirm if you can reproduce this with invoke-scriptanalyzer.

You are correct! Using Invoke-Formatter, it produced the same results...

if (-not(Get-Variable 'psEditor')) { # -not should have spaces around it
    do {
        Start-Sleep -Milliseconds 250
    }until( # until should have spaces around it
        (Get-Variable 'psEditor')
    )
    do {
        Start-Sleep -Milliseconds 250
    }while ( # while should have spaces around it
        -not(Get-Variable 'psEditor') # -not should have a space after it
    )
}

So, I should open an issue with PSScriptAnalyzer I take it?

@JustinGrote JustinGrote added Pending: External This issue is not fixed here, it is fixed in a dependent repo such as PowerShell,PSScriptAnalyzer and removed Needs: Author Feedback Please give us the requested feedback! labels Apr 15, 2025
@TMA-2
Copy link
Contributor Author

TMA-2 commented Apr 15, 2025

Opened issue 2095 with PSScriptAnalyzer. Closing...

@TMA-2 TMA-2 closed this as completed Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Script Analysis Issue-Bug A bug to squash. Pending: External This issue is not fixed here, it is fixed in a dependent repo such as PowerShell,PSScriptAnalyzer
Projects
None yet
Development

No branches or pull requests

2 participants