PowerShell / PowerShell/PSScriptAnalyzer

PSAvoidAssignmentToAutomaticVariable Should detect auto-vars as function parameters

Open
#1,026 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I did this recently and needed about 30 minutes to find my bug:

function Demo
{
    Param (
    [string] $input
    )
}

You can pass everything to this parameter, no warning, no error and $input is always $null !

See here, too: https://github.com/PowerShell/PSScriptAnalyzer/issues/712 "New Rule Suggestion: AvoidReuseOfAutomaticVariables"

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 locating the PSAvoidAssignmentToAutomaticVariable rule and review the related issue #712. Reproduce the function-parameter example from this issue, then determine how the rule currently detects automatic-variable assignments. Done means the example produces a warning while valid parameters remain unaffected, with coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.