PowerShell / PowerShell/PSScriptAnalyzer
Suppressing PSAvoidGlobalVars for a single variable
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 2.2k
- 派生
- 414
- 平均合并
- 13 小时 1 分钟
- 30 天内合并 PR
- 2
描述
Hi, I've got a legacy script which I've started running through PSScriptAnalyzer, and I've got a bunch of global variables which I'm gradually refactoring away. However, one of them is proving difficult to deal with so I'd like to suppress the PSAvoidGlobalVars error on just that one for now, while leaving the others still erroring to remind me I need to come back and fix them later.
I don't really want to exclude the rule entirely, so I've tried this...
myScript.ps1
$global:myGlobalVar1 = "abc";
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "")]
$global:myGlobalVar2 = "pqr";
$global:myGlobalVar3 = "xyz";
... but it doesn't seem to suppress the error for $global:myGlobalVar2.
Is there another way to do this?
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 myScript.ps1 中的抑制示例开始,调查 PSAvoidGlobalVars 规则如何处理 SuppressMessageAttribute。查看项目记录的抑制行为以及相关测试(如果有)。完成的标准是确定是否只有 $global:myGlobalVar2 可以被抑制,并在不全局禁用该规则的情况下记录或验证受支持的方法。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- powershell
- 领域
- tooling
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100