Skip to content
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

foreach Variable Assignment isn't Validated by PSAvoidAssignmentToAutomaticVariable #2020

Open
PoshAJ opened this issue Aug 10, 2024 · 1 comment · May be fixed by #2021
Open

foreach Variable Assignment isn't Validated by PSAvoidAssignmentToAutomaticVariable #2020

PoshAJ opened this issue Aug 10, 2024 · 1 comment · May be fixed by #2021

Comments

@PoshAJ
Copy link

PoshAJ commented Aug 10, 2024

Steps to reproduce

Invoke-ScriptAnalyzer -ScriptDefinition 'foreach ($Host in $foo) {}'

Expected behavior

The Variable 'Host' cannot be assigned since it is a readonly automatic variable that is built into PowerShell, please use a different name.

Actual behavior


Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.4.4
PSEdition                      Core
GitCommitId                    7.4.4
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.22.0
@PoshAJ PoshAJ changed the title Implicit Variable Assignment by foreach isn't Validated by PSAvoidAssignmentToAutomaticVariable foreach Variable Assignment isn't Validated by PSAvoidAssignmentToAutomaticVariable Aug 10, 2024
@PoshAJ PoshAJ linked a pull request Aug 10, 2024 that will close this issue
6 tasks
@SydneyhSmith
Copy link
Collaborator

Thanks this is a tricky one because of scoping--- we will take a look a the PR, thanks for opening

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

Successfully merging a pull request may close this issue.

2 participants