PSScriptAnalyzer icon indicating copy to clipboard operation
PSScriptAnalyzer copied to clipboard

Add UseConsistentParameterSetName Rule

Open liamjpeters opened this issue 4 months ago • 0 comments

PR Summary

Add UseConsistentParameterSetName rule to detect potential parameter set issues

Parameter set names are case-sensitive in PowerShell (unlike most other elements), which can lead to runtime errors and unexpected behavior when not handled correctly.

The rule performs five key validations:

  1. Missing DefaultParameterSetName - Warns when parameter sets are defined but no default is specified
  2. Duplicate parameter declarations - Detects parameters declared multiple times in the same parameter set
  3. DefaultParameterSetName case mismatch - Warns when the DefaultParameterSetName matches the text but not case of a defined parameter set.
  4. ParameterSetName case inconsistency - Validates consistent casing across all references to the same parameter set
  5. Invalid characters - Prevents newline characters in parameter set names.

Fixes #396 with the exception of ParameterSets that don't have at least one unique parameter.

This won't help with Dynamic Parameters.

PR Checklist

liamjpeters avatar Aug 19 '25 21:08 liamjpeters