Pipeline formatting is broken with Select-Object and custom property with nested pipeline
See original GitHub issuePrerequisites
- 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
Issue Analytics
- State:
- Created a year ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Pipeline formatting is broken with Select-Object and ...
When formatting (Shift + Alt + f) code with pipelines and custom properties will go some tabs on the right or remove cmdlet....
Read more >Is the following possible in PowerShell: "Select-Object < ...
The scenario: I'm using Select-Object to access properties of a piped object, and one of those properties is itself an object.
Read more >ForEach-Object - Module: Microsoft.PowerShell.Core
The ForEach-Object cmdlet is useful for getting property values, because it gets the value without changing the type, unlike the Format cmdlets or...
Read more >Universal Dialog - powershell.one
Select-Object Breaks Code ... A common approach to prettifying gridview output is using Select-Object . However, that's often completely breaking ...
Read more >PSCustomObject: Save Puppies and Avoid Dead Ends
The Format cmdlets are almost as bad, although no deaths have yet been attributed to them. Instead, when you use a Format cmdlet,...
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 Free
Top 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
Ok, so what I can confirm is that with
pipelineIndentationStyle
being the non-default value ofIncreaseIndentationForFirstPipeline
orIncreaseIndentationAfterEveryPipeline
, then the 3rdGet-TransportRule
row gets indented one level too much, the rest is then just a follow on error because PSSA is counting indentation. For the settingNone
, I can confirm it removes code, theNoIndentation
setting was introduced as a better alternative and default to it so although the outcome is much more severe, I think it’s better to look at fixing the added indentation that brings follow on code out of line. Debugging and fixing those non-default settings takes time so bear with me please and if the current behavior is not satisfactory enough, I suggest to use the default setting. ThencreaseIndentation
settings introduced in the last years have come a long way with lots of similar bug fixes already and it seems there’s still more tweaking work to do…Sorry I closed the issue in VSCode repo and it closed it in the PSScript Analyzer repo too. I open it again.