PowerShell / PowerShell/PSScriptAnalyzer

Code Formatting : Whitespacing one line hashtable

Open
#1,113 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hello
I am looking for a improvment on the current formatting tools by adding a whitespace after open bracket and before closing non empty curly brackets like :

#Actual
$emptyHash = @{ }               # an empty Hash
$myHash = @{foo = "bar"}

#Expected
$emptyHash = @{}                # an empty Hash
$myHash = @{ foo = "bar" } #whitespace after `{ `and before ` }`

Additional information:

  • I use the PowerShell extension on VS Code to format automaticaly my code on save.

  • My settings.json file:

{
    "editor.formatOnSave": true,
    "powershell.codeFormatting.preset": "Custom",
    "powershell.codeFormatting.alignPropertyValuePairs": true,
    "powershell.codeFormatting.ignoreOneLineBlock": false,
    "powershell.codeFormatting.newLineAfterCloseBrace": true,
    "powershell.codeFormatting.newLineAfterOpenBrace": true,
    "powershell.codeFormatting.openBraceOnSameLine": false,
    "powershell.codeFormatting.whitespaceAfterSeparator": true,
    "powershell.codeFormatting.whitespaceAroundOperator": true,
    "powershell.codeFormatting.whitespaceBeforeOpenBrace": true,
    "powershell.codeFormatting.whitespaceBeforeOpenParen": true,
    "powershell.scriptAnalysis.enable": true,
    "files.trimTrailingWhitespace": true,
}

This feature exist on other language :
https://github.com/Microsoft/TypeScript/issues/9613#issuecomment-268460847

Regards,

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 does not name files or tests. Start by locating the PowerShell code-formatting handling for one-line hashtables and reproduce the examples in the issue with the listed custom settings. Done means non-empty curly-brace hashtables receive surrounding whitespace while empty hashtables remain unchanged, with coverage for both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
developer-experience, tooling
Issue type
Feature
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.