-
Notifications
You must be signed in to change notification settings - Fork 406
Open
Labels
Description
Problem to be solved
PowerShell (theoretically) supports parameters whose name can consist only from numbers. For example, this is a valid declaration:
function p1([switch]$1) {if ($1) {'Yes'} else {'No'}}However, it is very hard to call properly this script. This one will not work:
PS /home/iiric> p1
No
PS /home/iiric> p1 -1
No
This is because parser will think -1 is a negative number rather than a parameter name in this instance.
Proper (=hard) way would be to use splatting.
$params = @{ '1' = $true }
PS> p1 @params
YesGenerally, this is not the only example of such unusable parameters. See response by @vexx32 in PowerShell repo issue.
Summary of the new feature
Create a PSSA rule that warns when such parameters are created, so users are aware ahead of time that they're making parameters that they won't be able to refer to.
Reactions are currently unavailable