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.

Automatically split | characters to a new line

See original GitHub issue

Summary of the new feature/enhancement

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
thomasrea0113commented, Sep 20, 2019

@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?

1reaction
bergmeistercommented, Sep 20, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Split string using a newline delimiter with Python [duplicate]
If you want to split only by newlines, you can use str.splitlines(): ... data.split() # split automatically splits through \n and space ['a,b,c',...
Read more >
Split Java String by Newline | Baeldung
In this tutorial, we'll look at different ways to split a Java String by newline characters. Since the newline character is different in ......
Read more >
How to Split Multiple Lines in a Cell into a Separate Cells ...
Learn how to spit multiple lines in a single cell into different cells using Text to Columns functionality. You need to use Control...
Read more >
Split a String - Online String Tools
Simple, free and easy to use online tool that splits strings. No intrusive ads, popups or nonsense, just a string splitter. Load a...
Read more >
JavaScript - split string by new line character - Dirask
In this article, we're going to have a look at the problem of how to split string to separate lines in JavaScript. Note:...
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