Skip to content

Feature Request: Key/Value Vertical Alignment in Array of HashTable or Ignore White Space in Sinlge Line HashTables #1158

Open
@markekraus

Description

System Details

  • Operating system name and version: Windows
  • VS Code version: 1.19.1
  • PowerShell extension version: 1.5.1
  • Output from $PSVersionTable:
Name                           Value
----                           -----
PSVersion                      5.1.16299.98
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.98
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Copy / paste the following commands into the PowerShell Integrated Console, and paste the output here:

code -v
1.19.1
0759f77bb8d86658bc935a10a64f6182c5a1eeba
x64

$pseditor.EditorServicesVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
1      5      1      0


code --list-extensions --show-versions
DavidAnson.vscode-markdownlint@0.12.0
DotJoshJohnson.xml@1.9.2
eamodio.gitlens@7.2.0
JohnAaronNelson.apex@0.0.2
ms-vscode.azure-account@0.2.2
ms-vscode.csharp@1.13.1
ms-vscode.PowerShell@1.5.1
Pendrica.chef@0.6.4
redhat.java@0.16.0
robertohuertasm.vscode-icons@7.19.0
streetsidesoftware.code-spell-checker@1.6.2
vscjava.vscode-java-debug@0.5.0
vscjava.vscode-java-pack@0.2.0
yzhang.markdown-all-in-one@1.0.0

$PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.16299.98
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.98
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

When writing pester tests it is common to use an array of HashTables to supply to It -TestCases:

Describe "Tests" {
    BeforeAll {
        $TestCases = @(
            @{ Item1 ='11111'; Item2 = '11111111'; Item3 = '111111111111'; Item4 = '111111111111' }
            @{ Item1 ='1111'; Item2 = '1111111'; Item3 = '11111111111'; Item4 = '11111111111' }
            @{ Item1 ='111111'; Item2 = '1111111'; Item3 = '1111111111111'; Item4 = '11111111111' }
            @{ Item1 ='1111'; Item2 = '111111111'; Item3 = '11111111111'; Item4 = '1111111111111' }
        )
    }
    It "Uses TestCases" -TestCases $TestCases {
        param($Item1, $Item2, $Item3, $Item4)
        <# do test #>
    }
}

To improve readability of that array of HashTables, they are often formatted with a vertical alignment on the keys and values like so:

@(
    @{ Item1 ='11111';  Item2 = '11111111';  Item3 = '111111111111';  Item4 = '111111111111' }
    @{ Item1 ='1111';   Item2 = '1111111';   Item3 = '11111111111';   Item4 = '11111111111' }
    @{ Item1 ='111111'; Item2 = '1111111';   Item3 = '1111111111111'; Item4 = '11111111111' }
    @{ Item1 ='1111';   Item2 = '111111111'; Item3 = '11111111111';   Item4 = '1111111111111' }
)

However, the auto formatting options always remove the extra white space in the HashTables. This means that when formatting a file you either have to lose the alignment or discard the chunk in git before comiting.

Ideally, I'd like to have a way to auto-format arrays of hashtables like that, but I'm having trouble even coming up with the words to describe what I'm looking for with out using a visual reference.

At least, I could be happy with a formatting option to the tune of "Ignore white space in single-line HashTables". That would allow for manual formatting of the HashTables to not be overwritten by auto-formatting so the rest of the file can benefit from auto-formatting.

reference PowerShell/PowerShell#5716

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions