PowerShell / PowerShell/PSScriptAnalyzer
`Invoke-ScriptAnalyzer` parameterset ambiguity
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 2.2k
- 派生
- 414
- 平均合并
- 13 小时 1 分钟
- 30 天内合并 PR
- 2
描述
Summary
Both the -Path and -ScriptDefinition parameters of Invoke-ScriptAnalyzer are [string] parameters. Both accept ValueFromPipeline and both are declared as Position=0. While they exist in different parameter sets (each with two variants), there is no unique parameter in either set that would allow PowerShell to disambiguate and select the intended parameter set during binding.
As a result, the default parameter set (Path_SuppressedOnly) is always chosen. Any string passed down the pipeline (by value) or as a positional argument is bound to the Path parameter. This means that ScriptDefinition's Position=0 and pipeline (by value) binding declarations are effectively unreachable - any positional or pipeline string will always be bound to Path.
This isn't a bug, but is a design issue: the ScriptDefinition parameter advertises pipeline (by value) and positional binding, but there is no way for users to actually use these features due to parameter set ambiguity.
I propose removing ValueFromPipeline = true and Position = 0 from ScriptDefinition. This isn't a breaking change as they can't currently be used.
ValueFromPipelineByPropertyName is fine - the below works:
[PSCustomObject]@{ScriptDefinition = '$Var = 1'} | Invoke-ScriptAnalyzer
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 7.4.11
PSEdition Core
GitCommitId 7.4.11
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.24.0
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Invoke-ScriptAnalyzer 的参数声明开始,检查 Path 和 ScriptDefinition 参数集,包括它们的位置绑定和管道绑定元数据。完成的标准是 ScriptDefinition 不再声明无法到达的位置绑定或按值进行的管道绑定,同时仍可使用按属性名称绑定;请根据 issue 中的示例验证生成的命令行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- powershell
- 领域
- cli
- Issue 类型
- 重构
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100