79532401

Date: 2025-03-24 23:56:21
Score: 0.5
Natty:
Report link

For me what worked is to add an attribute [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'foo')] (where foo is the variable to supress) to the script scope (i.e. at the very top of the file, before anything else) and add an empty param() to the top of the file for the attribute to bind to.

You can't assign attributes to variables, and PSScriptAnalyzer doesn't understand the concept of Pester's named script blocks, so it has to be done up top.

Before:

An image showing a variable that VSCode's PSScriptAnalyzer run thinks isn't being used

After:

An image to show how to get PSScriptAnalyzer in VSCode to supress the unused variable. Notice how $foo is supressed but $bar isn't as there's no Attribute for that.

Notice how $foo is now being suppressed as intended, but $bar doesn't get suppressed as there is no attribute for it.

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Elven Spellmaker