PowerShell / PowerShell/PSScriptAnalyzer

Formatting .where and .foreach methods is incorrect

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

Nobody has claimed this yet.

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

Description

When using the methods .where and .foreach in VS Code there's an incorrect indentation of the closing brackets and a space is added after the method.

Expected behavior

@().foreach({

})

Actual behavior

@().foreach( {

    })

image

Environment data

Name                           Value
----                           -----
PSVersion                      5.1.14409.1018
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1018
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.17.1

Related to an issue in the PowerShell repo.

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

No source file or test is named in the report. Reproduce the .where and .foreach formatting examples in VS Code with PSScriptAnalyzer 1.17.1, then locate the formatter path responsible for spacing and closing-bracket indentation. Done means the output matches the expected examples without regressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.