PowerShell / PowerShell/PSScriptAnalyzer
new feature: unusable parameters warning
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 2.2k
- 派生
- 414
- 平均合并
- 13 小时 1 分钟
- 30 天内合并 PR
- 2
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先查看现有的 PSScriptAnalyzer 规则以及它们报告诊断信息的方式,然后检查链接的 PowerShell issue,了解被认为不可用的情况。完成的标准是:当某个参数无法以通常方式引用时,分析器会发出警告,其中包括类似 $1 的纯数字参数。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp, powershell
- 领域
- tooling
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100