Skip to content

AvoidAssignmentToAutomaticVariable doesn't distinguish between normal and DSC scripts #2105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cflanderscpc opened this issue May 22, 2025 · 1 comment

Comments

@cflanderscpc
Copy link

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.
@bergmeister
Copy link
Collaborator

We only have -Path parameter of command against which file/folder to run but no configuration in vs code like that or way of excluding files, it has been raised before for things like pesters tests but if this is about the editor experience, might be better to open issue in https://github.com/PowerShell/vscode-powershell instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants