PowerShell / PowerShell/PSScriptAnalyzer

Format Document with Hash Table entry on first line stopping all formatting in file

Open
#1,120 0 comments 0 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

Steps to reproduce

following data in VS Code editor will prevent any formatting of PowerShell code in the file. If I move the PivotRows = 'Date' to the next line proper formatting occurs throughout rest of file.

{
    $pt.SprintEffortCharts=@{  PivotRows         = 'Date'
                NoTotalsInPivot = $true
                PivotDataToColumn = $true
    }
    
    }

Output of Invoke-Formatter

Invoke-Formatter -ScriptDefinition "$(Get-Content $scriptPath)" -Verbose 2> .\invoke-formatter.log
VERBOSE: Using settings file at C:\Program Files\WindowsPowerShell\Modules\PSScriptAnalyzer\1.17.1\Settings\CodeFormatting.psd1.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSPlaceCloseBrace rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSPlaceOpenBrace rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSUseConsistentWhitespace rule.
VERBOSE: Found 2 violations.
VERBOSE: Fixed 1 violations.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSUseConsistentWhitespace rule.
VERBOSE: Found 1 violations.
VERBOSE: Fixed 1 violations.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSUseConsistentIndentation rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
VERBOSE: Analyzing Script Definition.
VERBOSE: Running PSAlignAssignmentStatement rule.
VERBOSE: Found 0 violations.
VERBOSE: Fixed 0 violations.
{ $pt.SprintEffortCharts = @{ PivotRows = 'Date' NoTotalsInPivot = $true PivotDataToColumn = $true } }
invoke-formatter.log

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.16299.820
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.820
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
1.17.1

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

Start by reproducing the provided hash-table example with Invoke-Formatter on PSScriptAnalyzer 1.17.1, then compare it with the version where PivotRows is moved to the next line. Trace the formatter behavior for the first-line hash-table entry. Done means the complete file formats correctly without collapsing the hash-table contents.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.