Skip to content

style: apply quoted-literals / named-parameters / validation rules to Initialize-Template.ps1 #24

@tablackburn

Description

@tablackburn

Background

instructions/powershell.instructions.md mandates three rules for in-tree code:

  • Literal string parameter values are single-quoted
  • Cmdlet calls use named parameters (when more than one argument is passed)
  • Every function parameter has an appropriate validator

PR #23 brought the template's first-party files into compliance (build.ps1, the example {{Prefix}} module source, scaffold tests, helper modules) but explicitly deferred Initialize-Template.ps1 because it's a one-shot init script with very different shape and risk profile, and folding it into that PR would have ballooned the scope.

This issue tracks closing the gap.

What needs to change

Audit Initialize-Template.ps1 for:

  • Unquoted string literals in cmdlet parameter values — e.g., -Path foo-Path 'foo'
  • Multi-arg cmdlet calls using positional parameters — e.g., Split-Path -Parent $xSplit-Path -Path $x -Parent
  • param() blocks missing [ValidateNotNull*] / [ValidateRange] / [ValidateSet] validators
  • Write-Verbose / Write-Output / similar single-arg calls — these can stay positional per the documented rule (only multi-arg calls require naming)

Verification

  • Parse-check the file before/after with [Parser]::ParseFile
  • Exercise Initialize-Template.ps1 end-to-end (clone → run init → confirm a usable scaffolded module) to catch any behavioural regression
  • PSScriptAnalyzer should remain clean

Reference

PR #23 (this PR) and tablackburn/JsmOperations#2 show the canonical shape of these changes applied to other code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions