Skip to content

Invoke-Formatter removes code when whitespaceBetweenParameters is used #1582

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
PrzemyslawKlys opened this issue Sep 6, 2020 · 2 comments
Closed

Comments

@PrzemyslawKlys
Copy link
Contributor

Before submitting a bug report:

  • Make sure you are able to repro it on the latest released version
  • Perform a quick search for existing issues to check if this bug has already been reported

Steps to reproduce

function Test {
    param(
        [scriptblock] $Test,
        [switch] $Test1,
        [switch] $Test2
    )
    if ($Test1) {
    Write-Host "Test me 1"
    }
    if ($Test2) {
        Write-Host 'Test me 2'
    }
}

Test {

}  -Test1 -Test2

Try to format this and notice code gets removed. It seems if -Test1 is more then 1 space away from closing bracket things get sideways. This code executes properly so I would say it's valid PowerShell

Output:

function Test {
    param(
        [scriptblock] $Test,
        [switch] $Test1,
        [switch] $Test2
    )
    if ($Test1) {
        Write-Host "Test me 1"
    }
    if ($Test2) {
        Write-Host 'Test me 2'
    }
}

Te-Test1 -Test2

It's related to "powershell.codeFormatting.whitespaceBetweenParameters": true

Expected behavior

Remove too many spaces, leave my code alone :-)

Actual behavior

Removes a lot more

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.19041.1
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.1
1.19.1
@ghost ghost added the Needs: Triage 🔍 label Sep 6, 2020
@geeebse
Copy link

geeebse commented Sep 6, 2020

Before submitting a bug report:

  • Make sure you are able to repro it on the latest released version

  • Perform a quick search for existing issues to check if this bug has already been reported

Steps to reproduce


function Test {

    param(

        [scriptblock] $Test,

        [switch] $Test1,

        [switch] $Test2

    )

    if ($Test1) {

    Write-Host "Test me 1"

    }

    if ($Test2) {

        Write-Host 'Test me 2'

    }

}



Test {



}  -Test1 -Test2

Try to format this and notice code gets removed. It seems if -Test1 is more then 1 space away from closing bracket things get sideways. This code executes properly so I would say it's valid PowerShell

Output:

function Test {

    param(

        [scriptblock] $Test,

        [switch] $Test1,

        [switch] $Test2

    )

    if ($Test1) {

        Write-Host "Test me 1"

    }

    if ($Test2) {

        Write-Host 'Test me 2'

    }

}



Te-Test1 -Test2

It's related to "powershell.codeFormatting.whitespaceBetweenParameters": true

Expected behavior


Remove too many spaces, leave my code alone :-)

Actual behavior


Removes a lot more

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Environment data


> $PSVersionTable

Name                           Value

----                           -----

PSVersion                      5.1.19041.1

PSEdition                      Desktop

PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}

BuildVersion                   10.0.19041.1

CLRVersion                     4.0.30319.42000

WSManStackVersion              3.0

PSRemotingProtocolVersion      2.3

SerializationVersion           1.1.0.1



> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }

1.19.1

1.19.1

@SydneyhSmith
Copy link
Collaborator

Thanks @PrzemyslawKlys this issue looks like a duplicate of issue #1561 unfortunately the formatter needs some updating, thanks for supplying the detailed info and re-pro

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

3 participants