Skip to content

Suppressing PSAvoidGlobalVars for a single variable #822

Open
@mikeclayton

Description

@mikeclayton

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions