PowerShell / PowerShell/PSScriptAnalyzer

Suppressing PSAvoidGlobalVars for a single variable

未關閉
#822 2 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

Area - Rules Issue - Enhancement
主要語言
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?

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 myScript.ps1 中的抑制範例開始,調查 PSAvoidGlobalVars 規則如何處理 SuppressMessageAttribute。檢閱專案記錄的抑制行為以及相關測試(如果有)。完成的標準是確定是否只有 $global:myGlobalVar2 可以被抑制,並在不全域停用該規則的情況下記錄或驗證受支援的方法。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
powershell
領域
tooling
Issue 類型
功能
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。