Author Topic: PowerShell array definition spacing issue  (Read 257 times)

spongyryno

  • Community Member
  • Posts: 26
  • Hero Points: 0
PowerShell array definition spacing issue
« on: December 18, 2021, 12:57:09 am »
Let's say you are editing a PowerShell file (*.ps1) that contains:



Code: [Select]
$myarray = @(
'one'
'two'
'three'
)

If you copy one of the lines of array elements and then paste another copy in... the spacing is all wrong. It looks like this:

Code: [Select]
$myarray = @(
'one'
'two'
'two'
'three'
)

Why is this? How can I fix it?

Note that if the array has commas, the issue does NOT repro:

Code: [Select]
$myarray = @(
'one',
'two',
'three'
)

However, PowerShell doesn't require arrays to have commas when the line break can be used as an element delimiter, and using commas makes maintaining the code more difficult because it requires different syntax for the last item. The correct syntax to use is not to use commas.

How can I fix this?

Thanks!

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6209
  • Hero Points: 482
Re: PowerShell array definition spacing issue
« Reply #1 on: December 18, 2021, 02:35:07 am »
We will look into this.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6209
  • Hero Points: 482
Re: PowerShell array definition spacing issue
« Reply #2 on: December 18, 2021, 05:06:01 pm »
Added hot fix for this. Will be in first hot fix build for 26.0.1

spongyryno

  • Community Member
  • Posts: 26
  • Hero Points: 0
Re: PowerShell array definition spacing issue
« Reply #3 on: December 19, 2021, 09:52:15 pm »
Thanks. Presumably, this is an edit to c.e, right? Any chance you can share that here so I can get a head start testing it?

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6209
  • Hero Points: 482
Re: PowerShell array definition spacing issue
« Reply #4 on: December 19, 2021, 10:00:41 pm »
You need to load both the attached macro files.

spongyryno

  • Community Member
  • Posts: 26
  • Hero Points: 0
Re: PowerShell array definition spacing issue
« Reply #5 on: December 22, 2021, 03:55:43 am »
Thanks! This works. BTW, I see the same sort of thing in Json files as well:

Code: [Select]
{
    MyArray: [
        "a",
        "b",
        "c",
        "d"
    ]
}