PowerShell / PowerShell/PSScriptAnalyzer

new feature: unusable parameters warning

未关闭
#1,375 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Issue - New Rule
主要语言
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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先查看现有的 PSScriptAnalyzer 规则以及它们报告诊断信息的方式,然后检查链接的 PowerShell issue,了解被认为不可用的情况。完成的标准是:当某个参数无法以通常方式引用时,分析器会发出警告,其中包括类似 $1 的纯数字参数。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp, powershell
领域
tooling
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。