PowerShell / PowerShell/PSScriptAnalyzer

Automatically split | characters to a new line

Open
#1,345 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue - New Rule
Dominant language
C#
Stars
2.2k
Forks
414
Avg merge
13h 1m
Merged PRs (30d)
2

Description

Summary of the new feature/enhancement

I should state that I am using VS Code. I was told that for this feature to be possible in VS Code, it has to first be implemented here. The setting I mention down below is a VS Code Powershell setting.

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue provides PowerShell examples and references the VS Code pipelineIndentationStyle setting; first locate the existing pipeline-formatting entry point and related tests in PSScriptAnalyzer. Compare current behavior with the requested splitting after |, {, and }, and define completion with tests covering the shown nested pipeline and indentation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.