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

PSAvoidAssignmentToAutomaticVariable finds auto variable in RHS when assigning to a static property #1013

Closed
SeeminglyScience opened this issue Jun 4, 2018 · 1 comment · Fixed by #1008
Assignees
Milestone

Comments

@SeeminglyScience
Copy link
Contributor

Steps to reproduce

Invoke-ScriptAnalyzer -ScriptDefinition '[System.Console]::CursorVisible = $true'

Expected behavior

The rule is not triggered

Actual behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSAvoidAssignmentToAutomaticVariable Error                  1     The Variable 'true' cannot be assigned since it is a
                                                                  readonly automatic variable that is built into
                                                                  PowerShell, please use a different name.

Environment data

> $PSVersionTable
Name                           Value                                                                                                                                                         
----                           -----                                                                                                                                                         
PSVersion                      5.1.16299.251                                                                                                                                                 
PSEdition                      Desktop                                                                                                                                                       
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                       
BuildVersion                   10.0.16299.251                                                                                                                                                
CLRVersion                     4.0.30319.42000                                                                                                                                               
WSManStackVersion              3.0                                                                                                                                                           
PSRemotingProtocolVersion      2.3                                                                                                                                                           
SerializationVersion           1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.17.0
1.13.0
@bergmeister bergmeister self-assigned this Jun 4, 2018
@bergmeister bergmeister added this to the 1.17.1 milestone Jun 4, 2018
bergmeister added a commit to bergmeister/PSScriptAnalyzer that referenced this issue Jun 4, 2018
bergmeister added a commit to bergmeister/PSScriptAnalyzer that referenced this issue Jun 4, 2018
bergmeister added a commit that referenced this issue Jun 5, 2018
… when assigning a .Net property and only look at the LHS (#1008)

* Fix NullReferenceException in AvoidAssignmentToAutomaticVariable rule when assigning a net property to a .Net property

* when variableExpressionAst is null, then continue loop to reduce nesting

* fix indentation for cleaner diff

* Fix issue #1013 as well by making sure the rule looks only the LHS

* Fix issue #1012 as well

* Simplify test that checks that PSSA does not throw to address PR review
@bergmeister
Copy link
Collaborator

bergmeister commented Jun 6, 2018

@SeeminglyScience Both your reported issues have been fixed as part of the new 1.17.1 release

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