Skip to content

Pipeline formatting is broken with Select-Object and custom property with nested pipeline #1832

Closed
@JeanPhilippeGeorge

Description

@JeanPhilippeGeorge

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

When formatting (Shift + Alt + f) code with pipelines and custom properties will go some tabs on the right or remove cmdlet.

Before:

function X {
	# Ok 
	Get-TransportRule | 
		Select-Object -Property @{N = 'SenderDomainIs'; E = { ($_.SenderDomainIs | Sort-Object ) -join ', ' } }, @{N = 'RecipientDomainIs'; E = { ($_.RecipientDomainIs | Sort-Object) -join ', ' } }, BlindCopyTo | 
		ConvertTo-Html -Fragment

	# After these lines will go one tab to the right
	Get-TransportRule | 
		Select-Object name, @{N = 'SenderDomainIs'; E = { ($_.SenderDomainIs | Sort-Object ) -join ', ' } } | ConvertTo-Html -Fragment
		
	# After these lines will  go one more tab to the right
	Get-TransportRule | 
		Select-Object name, @{N = 'SenderDomainIs'; E = { ($_.SenderDomainIs | Sort-Object ) -join ', ' } }
}

function Xx {

}

After with settings: "powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline"
Seems that if there is one more pipeline on next line it's ok.

function X {
	# Ok 
	Get-TransportRule | 
		Select-Object -Property @{N = 'SenderDomainIs'; E = { ($_.SenderDomainIs | Sort-Object ) -join ', ' } }, @{N = 'RecipientDomainIs'; E = { ($_.RecipientDomainIs | Sort-Object) -join ', ' } }, BlindCopyTo | 
		ConvertTo-Html -Fragment

	# After these lines will go one tab to the right
	Get-TransportRule | 
		Select-Object name, @{N = 'SenderDomainIs'; E = { ($_.SenderDomainIs | Sort-Object ) -join ', ' } } | ConvertTo-Html -Fragment
		
		# After these lines will go one more tab to the right
		Get-TransportRule | 
			Select-Object name, @{N = 'SenderDomainIs'; E = { ($_.SenderDomainIs | Sort-Object ) -join ', ' } }
		}

		function Xx {

		}

Or worst with settings: "powershell.codeFormatting.pipelineIndentationStyle": "None"
Select-Object and ConvertTo-Html have now disapeared!

function X {
	# Missing Select-Object and ConvertTo-Html
	Get-TransportRule | 
	-Property @{N = 'SenderDomainIs'; E = { ($_.SenderDomainIs | Sort-Object ) -join ', ' } }, @{N = 'RecipientDomainIs'; E = { ($_.RecipientDomainIs | Sort-Object) -join ', ' } }, BlindCopyTo | 
	-Fragment

	# Missing Select-Object 
	Get-TransportRule | 
	name, @{N = 'SenderDomainIs'; E = { ($_.SenderDomainIs | Sort-Object ) -join ', ' } } | ConvertTo-Html -Fragment
		
	# Missing Select-Object 
	Get-TransportRule | 
	name, @{N = 'SenderDomainIs'; E = { ($_.SenderDomainIs | Sort-Object ) -join ', ' } }
}

function Xx {

}

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.2.5
PSEdition                      Core
GitCommitId                    7.2.5
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

1.69.2
3b889b090b5ad5793f524b5d1d39fda662b96a2a
x64

Extension Version

ms-vscode.powershell@2022.7.2

Steps to Reproduce

Copy and paste sample and do shift + alt + f with various settings of "powershell.codeFormatting.pipelineIndentationStyle"

function X {
	# Ok 
	Get-TransportRule | 
		Select-Object -Property @{N = 'SenderDomainIs'; E = { ($_.SenderDomainIs | Sort-Object ) -join ', ' } }, @{N = 'RecipientDomainIs'; E = { ($_.RecipientDomainIs | Sort-Object) -join ', ' } }, BlindCopyTo | 
		ConvertTo-Html -Fragment

	# After these lines will go one tab to the right
	Get-TransportRule | 
		Select-Object name, @{N = 'SenderDomainIs'; E = { ($_.SenderDomainIs | Sort-Object ) -join ', ' } } | ConvertTo-Html -Fragment
		
	# After these lines will  go one more tab to the right
	Get-TransportRule | 
		Select-Object name, @{N = 'SenderDomainIs'; E = { ($_.SenderDomainIs | Sort-Object ) -join ', ' } }
}

function Xx {

}

Visuals

No response

Logs

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions