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.

powershell.codeFormatting.whitespaceBetweenParameters inappropriately removes + operators in string concatenation

See original GitHub issue

Issue Description

When formatting a document with powershell.codeFormatting.whitespaceBetweenParameters enabled, the formatter inappropriately removes + operators in string concatenation.

Steps to reproduce:

  1. Enter this code example: Write-Output ($env:computername + ", " + $env:username) (GitHub is collapsing the whitespace, but there are four spaces on each side of each plus sign)
  2. Enable powershell.codeFormatting.whitespaceBetweenParameters
  3. Format document

Expected result:

Write-Output ($env:computername + ", " + $env:username)

Actual result:

Write-Output ($env:computername ", " + $env:username) (which is syntactically invalid!)

Additionally, if you start out with the expected result and format the document, you get the following result:

Write-Output ($env:computername ", " $env:username) …which is even worse, as the operators have been removed entirely.

Attached Logs

1593619176-7b7e0c1b-7340-41cb-a9a0-c526c1c513bd1593619173652.zip editor services.log

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.19041
VSCode 1.46.1
PowerShell Extension Version 2020.6.0

PowerShell Information

Name Value
PSVersion 5.1.19041.1
PSEdition Desktop
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.19041.1
BuildVersion 10.0.19041.1
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
powershell ms-vscode 2020.6.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rjmholtcommented, Jul 20, 2020

I can reproduce with 1.19.0 but not with the latest version of master.

I trust you on this

1reaction
rjmholtcommented, Jul 1, 2020
> pwsh-preview.cmd
PowerShell 7.1.0-preview.5
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

C:\Users\Robert Holt\Documents\Dev\Microsoft\PSScriptAnalyzer [master ≡ +3 ~0 -0 !]
> gmo PSSCriptAnalyzer
C:\Users\Robert Holt\Documents\Dev\Microsoft\PSScriptAnalyzer [master ≡ +3 ~0 -0 !]
> ipmo .\out\PSScriptAnalyzer\
C:\Users\Robert Holt\Documents\Dev\Microsoft\PSScriptAnalyzer [master ≡ +3 ~0 -0 !]
> Invoke-Formatter -ScriptDefinition 'Write-Output ($env:computername + ", " + $env:username)' -Settings @{
>>  Rules = @{
>>    PSUseConsistentWhitespace = @{
>>      Enable = $true
>>      CheckParameter = $true
>>    }
>>   }
>> }
Write-Output ($env:computername ", " + $env:username)

Looks like I can unfortunately

Read more comments on GitHub >

github_iconTop Results From Across the Web

Powershell string concatenation mystery
The implication is that $ver contains an array of strings, not just a single string: The -replace operator can operate on arrays as...
Read more >
How to Concatenate a String in PowerShell
Learn how to easily concatenate a string, variable, objects and more with PowerShell. All methods explained!
Read more >
Strings in PowerShell – Replace, compare, concatenate, ...
PowerShell automatically inserts a space here between the linked array elements. Another option for concatenating strings is the join operator.
Read more >
PowerShell Concatenate String: Examples & Functions
Concatenation is a method of joining two strings using certain operators. The PowerShell concatenation of strings happens with string builder, string with ...
Read more >
Concatenate - PowerShell
String Substitution has one important limitation: PowerShell will identify each variable in the expression by matching characters, that are legal for a $ ......
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