PSScriptAnalyzer
PSScriptAnalyzer copied to clipboard
Add UseConsistentParameterSetName Rule
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:
- Missing DefaultParameterSetName - Warns when parameter sets are defined but no default is specified
- Duplicate parameter declarations - Detects parameters declared multiple times in the same parameter set
- DefaultParameterSetName case mismatch - Warns when the DefaultParameterSetName matches the text but not case of a defined parameter set.
- ParameterSetName case inconsistency - Validates consistent casing across all references to the same parameter set
- 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
- [x] PR has a meaningful title
- Use the present tense and imperative mood when describing your changes
- [x] Summarized changes
- [x] Change is not breaking
- [x] Make sure all
.cs,.ps1and.psm1files have the correct copyright header - [x] Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
- [x] This PR is ready to merge and is not Work in Progress.
- If the PR is work in progress, please add the prefix
WIP:to the beginning of the title and remove the prefix when the PR is ready.
- If the PR is work in progress, please add the prefix