PowerShell / PowerShell/PSScriptAnalyzer

PSUseConsistentWhitespace - Ability to ignore if in a line with multiple pipes

Open
#2,162 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Summary of the new feature

The various PSUseConsistentWhitespace rules have various issues that might never be solved:

My biggest issue is that I don't want it to touch one liners or multiliners like this:

(
    (
        Invoke-RestMethod -Method 'Get' -Uri 'https://api.github.com/repos/chocolatey/choco/releases'
    ) | Where-Object -Property 'prerelease' -NE $true
).'tag_name' | Sort-Object -Property @{'Expression' = {[System.Version]$_}} -Descending | Select-Object -First 1

Which becomes this:

(
    (
        Invoke-RestMethod -Method 'Get' -Uri 'https://api.github.com/repos/chocolatey/choco/releases'
    ) | Where-Object -Property 'prerelease' -NE $true
).'tag_name' | Sort-Object -Property @{'Expression' = { [System.Version]$_ } } -Descending | Select-Object -First 1

If I could tell PSScriptAnalyzer to ignore cases like that I'd be happy.

Current impact

This makes it so that I don't use the code formatting presets, and instead define all the rules manually and disable most of the PSUseConsistentWhitespace rules.

Side note: Would be great with the ability to override built-in presets, so you don't have to specify all the rules.

Proposed technical implementation details (optional)

Don't know. Some ideas:

  • Ability to ignore if more than one pipe `| is found on the same line?

What is the latest version of PSScriptAnalyzer at the point of writing

v1.24.0

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

Review the current PSUseConsistentWhitespace rules and the linked open issues to understand how whitespace is applied across pipelines. Define the exact behavior for lines containing multiple pipes, then verify that the proposed ignore behavior preserves existing formatting checks without affecting other cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
devtools, 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.