vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Formatting fails when parameter defaults are set to a statement

Open cohowap opened this issue 9 years ago • 3 comments

System Details

  • Operating system name and version: Windows 10 Enterprise 10.0.14393
  • VS Code version: 1.9.1
  • PowerShell extension version: 0.9.0
  • Output from $PSVersionTable:
Name                           Value
----                           -----
PSVersion                      5.1.14393.693
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.693
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

When I Format a document that contains a default value (that is actually a statement), formatting differs than if you do not have it (it is left aligned by an additional tab).

In this case, formatted for parameter "$Here" is incorrect, as is any code below it. Removing "$(throw ..)" fixes the issue.

function Do-Something {
  param(
    [Parameter(Position=0)]
    $Over = $(throw "The parameter -Over is required."),
  [Parameter(Position=1)]
  $Here = $(throw "The parameter -Here is required.")
)
}

Attached Logs

Not sure logs are required, this is reproducible on multiple systems. Just paste above and format document with and without the "$(throw ...)" part.

cohowap avatar Feb 28 '17 21:02 cohowap

This issue has been fixed in PowerShell/PSScriptAnalyzer#700 and the next release of the extension will contain the fix.

kapilmb avatar Feb 28 '17 21:02 kapilmb

@kapilmb Thanks! Sorry for duplicate issue, I didn't see that one. Feel free to close, or I can.

cohowap avatar Feb 28 '17 21:02 cohowap

Probably wasn't easy to find while searching due to its title. I'll close this now, let us know if you still see the issue after the 0.10.0 update. Should be out in a few days. Thanks!

daviwil avatar Feb 28 '17 21:02 daviwil