PowerShell / PowerShell/PSScriptAnalyzer
Rule request: PossibleArgumentWithOperatorConfusion
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 2.2k
- 派生
- 414
- 平均合并
- 13 小时 1 分钟
- 30 天内合并 PR
- 2
描述
PowerShell has two parsing modes:
It is not always clear whenever PowerShell is in argument mode, as in:
if (&{ (1,2,3).Where{ $_ -eq 4 } } -isnot [int]) { Throw "The expression should return an integer"
For background information, see: Call operator (&{}) with no results doesn't type compare #24054
Yet from the argument name (and position and the operators) you could make a reasonable assumption that it probably concerns an operator instead.
For a (PowerShell based) rule prototype, see: https://github.com/iRon7/PSRules/blob/main/PossibleArgumentWithOperatorConfusion.psm1
Invoke-ScriptAnalyzer -CustomRulePath $RulePath -ScriptDefinition 'if (&{ (1,2,3).Where{ $_ -eq 4 } } -isnot [int]) { Throw "The expression should return an integer" }' | Select-Object *
Line : 1
Column : 5
Message : Possible argument with operator (-isnot) confusion.
Extent : &{ (1,2,3).Where{ $_ -eq 4 } } -isnot [int]
RuleName : PSPossibleArgumentWithOperatorConfusion
Severity : Warning
ScriptName :
ScriptPath :
RuleSuppressionID :
SuggestedCorrections : {(&{ (1,2,3).Where{ $_ -eq 4} }) -isnot [int]}
IsSuppressed : False
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 PossibleArgumentWithOperatorConfusion.psm1 中的 PowerShell 规则原型开始,并查看链接的 PowerShell 解析问题以了解背景。将原型的诊断、范围和建议的修正与现有的 PSScriptAnalyzer 规则进行比较;当所请求的混淆能够通过适当的警告和修正被检测到时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- powershell
- 领域
- tooling
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100