Skip to content

Cmdlet aliases are expanded automatically when formatting document #1842

Closed
PowerShell/PSScriptAnalyzer
#1216
@mkht

Description

@mkht

System Details

VSCode version

1.32.3 a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4 x64

VSCode extensions

ms-vscode.powershell@1.12.0

No other extensions is installed.
The vscode settings have not changed anything.

PSES version

1.12.0.0

PowerShell version:

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

Issue Description

All aliases in my PS codes are expanded unexpectedly when executing "Format Document".

I tried formatting the code below.

1..10|%{$_*2}

Expected result

I expect this code will format like this.

1..10 | % { $_ * 2 }

Actual result

But vscode-powershell@1.12.0.0 formatted.

1..10 | ForEach-Object { $_ * 2 }

I know that formatting is provided by the PSScriptAnalyzer module.
However, I think this issue is specific to vscode-powershell.
I execute these commands in the Windows PowerShell terminal. (Not in the integrated terminal)

PS C:\> Install-Module PSScriptAnalyzer -Scope CurrentUser
PS C:\> Get-Module PSScriptAnalyzer -ListAvailable

    Directory: C:\Users\Administrator\Documents\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.18.0     PSScriptAnalyzer                    {Get-ScriptAnalyzerRule, Invoke-ScriptAnalyzer, Invoke-Formatter}

PS C:\> Invoke-Formatter '1..10|%{$_*2}'
1..10 | % { $_ * 2 }

In this result, The original formatter of the PSScriptAnalyzer@1.18.0 is not expand aliases automatically.

Is this bug? Does anyone have an idea of how to work around it?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions