I'd like to the ability to take the following line:
$Ports | ForEach-Object -Process { NETSTAT.EXE -ano | findstr.exe :8080 | ForEach-Object -Process { ($_ -split '\s+')[-1] } | Sort-Object | Get-Unique | ForEach-Object -Process { taskkill.exe /F /PID $_ } }
and convert it to:
$Ports |
ForEach-Object -Process {
NETSTAT.EXE -ano |
findstr.exe :8080 |
ForEach-Object -Process {
($_ -split '\s+')[-1]
} | Sort-Object |
Get-Unique |
ForEach-Object -Process {
taskkill.exe /F /PID $_
}
}
I think this would go a long way in approving readability. At the very least, with the
"powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline"
setting enabled, when I manually add the new line after each | and }, it will format the indentation correctly which is nice.
@thomasrea0113 this type of change would first need to be done in https://github.com/PowerShell/PSScriptAnalyzer which provides the formatting experience in the PowerShell extension for VSCode.
Once a formatting rule is added there, then we can add a vscode setting to configure it.
Can you open an issue issue over there first?
cc @bergmeister
Indeed, please transfer it to PSSA. As it was already said the pipelineIndentationStyle setting of IncreaseIndentationForFirstPipeline already formats it correctly when there are already newlines but it does not break a 1 liner into multiple lines. I'd need to do some research if that is feasible (I believe there are good reasons to not try to force newlines to the user because what if one has a few short pipelines on line 2 that one does not want to be broken up due to the increase in indentation, one might need a new setting like pipelineNewlineStyle, I hope we are not drifting off here into configuration hell...)
Indeed, please transfer it to PSSA. As it was already said the
pipelineIndentationStylesetting ofIncreaseIndentationForFirstPipelinealready formats it correctly when there are already newlines but it does not break a 1 liner into multiple lines. I'd need to do some research if that is feasible (I believe there are good reasons to not try to force newlines to the user because what if one has a few short pipelines on line 2 that one does not want to be broken up due to the increase in indentation, one might need a new setting likepipelineNewlineStyle, I hope we are not drifting off here into configuration hell...)
A new setting like you mentioned is exactly what I'd be looking for. I'm thinking the setting could automatically split one-liners into multiple of the line reaches the standard 80 character limit.
@thomasrea0113 this type of change would first need to be done in https://github.com/PowerShell/PSScriptAnalyzer which provides the formatting experience in the PowerShell extension for VSCode.
Once a formatting rule is added there, then we can add a vscode setting to configure it.
Can you open an issue issue over there first?
cc @bergmeister
Done. I created the issue here: https://github.com/PowerShell/PSScriptAnalyzer/issues/1345
in the meantime, should this issue be closed?
Thanks for transferring the issue, yes, we can close here. Should that new setting be implemented in PSSA, it should be natural to the implementer that PRs would later be needed here and in PSES to propagate the setting.
Most helpful comment
Done. I created the issue here: https://github.com/PowerShell/PSScriptAnalyzer/issues/1345
in the meantime, should this issue be closed?