Skip to content

Add Format-PowerShellDataFile function for normalization #13

Description

Hand-written PSD1 files often have inconsistent indentation, key alignment, and value formatting. A Format-PowerShellDataFile function normalizes the text without changing semantics — equivalent to ConvertFrom-PowerShellDataFile | ConvertTo-PowerShellDataFile but expressed as a single ergonomic call.

Sister modules already follow this pattern: Format-Json and Format-Hashtable. PSD1 is the natural place to land canonical-form module manifests in CI workflows.

Request

Desired capability

Get-Content module.psd1 -Raw | Format-PowerShellDataFile
Format-PowerShellDataFile -Path module.psd1 -Indent 4

Parameters

Parameter Description
-InputObject String to format (ValueFromPipeline, default set)
-Path File path to read and format
-LiteralPath Literal file path
-Indent Spaces per nesting level (default: 4 — PSD1 convention)
-AlignValues Pad keys with spaces so values align in columns within the same hashtable (default: $false)

Acceptance criteria

  • Format-PowerShellDataFile $s produces canonical PSD1 for $s
  • Idempotent: Format-PowerShellDataFile (Format-PowerShellDataFile $s) equals Format-PowerShellDataFile $s
  • Output round-trips: ConvertFrom-PowerShellDataFile produces equivalent objects from input and formatted output
  • Output passes Test-ModuleManifest when the input is a valid module manifest
  • -Indent controls spacing between nested table levels
  • -AlignValues produces aligned-column output (matches the New-ModuleManifest style)

Technical decisions

Implementation: Parses input with ConvertFrom-PowerShellDataFile and re-emits with ConvertTo-PowerShellDataFile using the requested indentation and alignment. Reuses existing logic — no new parser or emitter.

Function placement: src/functions/public/Format-PowerShellDataFile.ps1.

Parameter sets: InputObject (default, pipeline) and Path / LiteralPath for file input.

Indent default: 4 spaces — matches the convention used by New-ModuleManifest output.

Alias: Format-Psd1.


Implementation plan

  • Add Format-PowerShellDataFile in src/functions/public/Format-PowerShellDataFile.ps1 with Format-Psd1 alias
  • Add Pester tests — basic format, custom -Indent, -AlignValues, idempotent round-trip, manifest validation after format
  • Update README and examples/General.ps1

Related

  • ConvertFrom/ConvertTo-PowerShellDataFile (prerequisite — separate issue)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions