PowerShell / PowerShell/PSScriptAnalyzer
Suggestion for new rule - Ensure that variables used in a function is always declared in the local scope
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 2.2k
- 派生
- 414
- 平均合并
- 13 小时 1 分钟
- 30 天内合并 PR
- 2
描述
In order to reduce the number of hard to debug errors, we run our PowerShell scripts with Set-StrictMode -Version Latest. This lets us catch issues where we e.g. have misspelled a variable name (or forgot to assign it before using it) during runtime. But it would be immensely useful to catch these kinds of errors before we run the scripts, e.g. during an automated build.
We have deployment scripts that run for quite a long time (several hours), and silly misspelled variable names or misplaced variable assignments then costs quite a bit of development time. Catching these errors early would be immensely useful.
Example of something that should cause an error:
function Get-Foobar()
{
if ($b + 2 -gt 5)
{
return $b
}
return 5
}
This would be OK:
function Get-Foobar($b)
{
if ($b + 2 -gt 5)
{
return $b
}
return 5
}
As would this:
function Get-Foobar()
{
$b = 123;
if ($b + 2 -gt 5)
{
return $b
}
return 5
}
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中的两个 PowerShell 示例开始,检查仓库中现有的 analyzer 规则和测试,以确定新规则应放在哪里。定义应如何处理参数、赋值和变量引用;完成的标准是报告未声明变量的示例,同时两个有效示例都通过,并为所选择的行为提供覆盖率。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- powershell
- 领域
- devtools
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100