PowerShell / PowerShell/PSScriptAnalyzer

Module exported variables should not be flagged with PSUseDeclaredVarsMoreThanAssignment

Open
#819 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area - PSUseDeclaredVarsMoreThanAssignments Area - Rules
Dominant language
C#
Stars
2.2k
Forks
414
Avg merge
13h 1m
Merged PRs (30d)
2

Description

Repro: In a module, define and assign a variable then export it using Export-ModuleMember -Variable


$MyVariable = 'some value'
Export-ModuleMember -Variable MyVariable

Expected: Invoke-ScriptAnalyzer does not flag the variable as unused.
Actual:
file: 'file:MyModule.psm1'
severity: 'Warning'
message: 'The variable 'MyVariable' is assigned but never used. (PSUseDeclaredVarsMoreThanAssignments)'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the MyModule.psm1 example: assign MyVariable and export it with Export-ModuleMember -Variable. Trace the PSUseDeclaredVarsMoreThanAssignments rule and its existing tests, then verify that an exported module variable is no longer reported as assigned but never used.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
devtools, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.