PowerShell / PowerShell/PSScriptAnalyzer
new feature: unusable parameters warning
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
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
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing existing PSScriptAnalyzer rules and how they report diagnostics, then examine the linked PowerShell issue for the cases considered unusable. Done means the analyzer warns when a parameter cannot be referred to normally, including a numeric-only parameter such as $1.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100