PowerShell / PowerShell/PSScriptAnalyzer
AvoidAssignmentToAutomaticVariable doesn't distinguish between normal and DSC scripts
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
Description
The AvoidAssignmentToAutomaticVariable rule doesn't distinguish between a normal script and a DSC script, meaning DSC specific auto-variables like $allNodes will cause complaints when the rule runs. I don't know if this is even something that could have logic applied to it in an effort to suppress, given there isn't necessarily an easy way to discern context of DSC vs Non-DSC scripts
Steps to reproduce
Create a standard powershell script ps1 file and enter the following. If in VS Code PSScriptAnalyzer automatically runs against it.
$allNodes = "Put anything here"
Expected behavior
Rule does not complain about usage of $allNodes as script is not used in DSC.
Actual behavior
The Variable 'allNodes' is an automatic variable that is built into PowerShell, assigning to it might have undesired side effects. If assignment is not by design, please use a different name.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the AvoidAssignmentToAutomaticVariable rule and reproduce the issue with a standard PowerShell .ps1 containing an assignment to $allNodes. Determine whether the rule can distinguish DSC scripts from normal scripts, then verify that the normal-script case no longer reports this variable without changing the intended DSC behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100