PowerShell / PowerShell/PSScriptAnalyzer

No 'Variable Referenced Before Assignment' Rule?

Open
#1,660 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

From what I can tell, there's no linting rule to check if a variable is null or unassigned when it's being referenced. This would be super helpful to avoid nullref errors when running a script or module. I know there's a "variable assigned but not referenced/used" rule, but that's kind of the opposite of what I'm looking for.

I know this functionality exists in pylint for python, but I sorely miss this when working with PowerShell.

Does this exist? If so, how does one enable it?

Apologies if there is already an issue for this somewhere. I couldn't find one.

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 reviewing PSScriptAnalyzer's existing rule for variables that are assigned but not referenced, then check whether a corresponding unassigned-variable rule already exists and how rules are enabled. Define done as either documenting the existing rule or specifying and implementing a rule that reports variables referenced before assignment, with coverage for the reported null-reference case.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.