PSScriptAnalyzer: Auto Format corrupting paths in my scripts

Issue Type: Bug Error

  1. Call a file in your script with “.” or “&” with a relative path like & ..\Desktop\Temp\Test.ps1 (The file need to exist).
  2. Trigger the Formatter by hitting Enter or Alt+Shift+F or any other way.
  3. The path to the file is deleted.

This is a major issue as opening a big script, changing a line (That triggers the auto format) will result in all paths in the document to corrupt braking the script! And if you saved and don’t have a backup you are in trouble.

Extension version: 1.12.0 VS Code version: Code 1.32.3 (a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4, 2019-03-14T23:43:35.476Z) OS version: Windows_NT x64 10.0.17763

EditorServices.log vscode-powershell.log

System Info
Item Value
CPUs AMD Ryzen 7 1800X Eight-Core Processor (16 x 3593)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: enabled
surface_synchronization: enabled_on
video_decode: enabled
webgl: enabled
webgl2: enabled
Memory (System) 15.95GB (9.09GB free)
Process Argv
Screen Reader no
VM 50%

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 20 (5 by maintainers)

Most upvoted comments

I’m still able to repro:

C:\Users\Keith
06-03 19:54:43 21> $def = Get-Content .\PSSA-Formatting.ps1 -Raw
C:\Users\Keith
06-03 19:55:18 22> $def
. .\Desktop\Temp\Test.ps1
. '.\Desktop\Temp\Test.ps1'
. .\Desktop\Temp\Test.ps1

get-process -name notepad

C:\Users\Keith
06-03 19:55:23 23> Invoke-Formatter -ScriptDefinition $def -Settings .\PSSA-Formatting-Settings.psd1
. Test.ps1
. Test.ps1
. Test.ps1

Get-Process -name notepad

C:\Users\Keith
06-03 19:55:35 24> gmo

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.1.0      DirColors                           {ConvertFrom-LSColors, ConvertTo-LSColors, Format-Colorize… Manifest   6.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemPropert… Manifest   6.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object…}
Script     1.0.0.0    posh-git                            {Add-PoshGitToProfile, Expand-GitCommand, Format-GitBranch… Script     2.0.0      PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PS…
Script     1.18.0     PSScriptAnalyzer                    {Get-ScriptAnalyzerRule, Invoke-Formatter, Invoke-ScriptAn…

Here is my setting file:

PSSA-Formatting-Settings.zip

@bergmeister I updated to the last VSCode PowerShell v2019.5.0 Tested with default setting - No formatting at all. (As it was turned off until this is fixed) Added "powershell.codeFormatting.useCorrectCasing": true to settings and tested again - formatting worked and paths get corrupted. Replaced the module in C:\Users\illym\.vscode\extensions\ms-vscode.powershell-2019.5.0\modules\PSScriptAnalyzer with AppVeyor version - problem not fixed paths still corrupted.

I just downgraded to VSCode PowerShell 1.11.0 The state of this software “Stable” releases is ridiculous. Every developer group I know who would make a release and get a bug of this magnitude discovered would rollback the update or release a patch version immediately. but here they just let more users data get damaged every day without taking action. If this was a single developer volunteering it’s time I can understand that. but this is a team with the backing of Microsoft.