question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cmdlet aliases are expanded automatically when formatting document

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14

github_iconTop GitHub Comments

2reactions
rjmholtcommented, Apr 10, 2019

Would you rather prefer new features to be not enabled by default in the first iteration?

Yeah, I think making the feature available in the first iteration and then enabling it in the second iteration is the wisest choice. It’s not an uncommon pattern. A good example is the way Rust handles feature stabilisation.

0reactions
ili101commented, Dec 19, 2019

@bergmeister I looked over the setting list twice and missed it somehow… thank you. Unfortunately after enabling it I found out it’s good thing it’s off because like the old bugs leading to it being disabled using it still brakes my scripts 😕 & ..\..\Target.ps1 becomes & Get-..\..\Target.ps1 https://github.com/PowerShell/PSScriptAnalyzer/issues/1369

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode Powershell Auto Correct Aliases Parameter not ...
I started using the shortcut Shift + Alt + E . This worked perfectly for me and every once in a while I...
Read more >
vscode how to expand all aliases in working document - Reddit
in a script, i typed sleep and it underlines it saying that it's an alias. i realize i have multiple aliases.
Read more >
Using PowerShell Aliases: Best Practices - Scripting Blog
An alias is a shortcut name, or a nickname, for a Windows PowerShell cmdlet. It enables me to type a short name instead...
Read more >
Windows PowerShell Cheat Sheet
In the Windows (File) Explorer address bar enter cmd , powershell.exe ... a list of aliases starting with 's' or 'S' can be...
Read more >
A Complete Guide to PowerShell unzip - eduCBA
PowerShell unzip extracts the files and folders from the specific Zip file on ... might not exist but the Expand-Archive command creates it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found