Cmdlet aliases are expanded automatically when formatting document
See original GitHub issueSystem 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:
- Created 4 years ago
- Comments:14
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@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