Skip to content

new feature: unusable parameters warning #1375

@iricigor

Description

@iricigor

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
Yes

Generally, 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions