You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PSAvoidAssignmentToAutomaticVariable Should detect auto-vars as function parameters #1026
madmidi in PSScriptAnalyzer 1.17.1 there is already a new rule PSAvoidAssignmentToAutomaticVariable that catches assignments against the automatic variables listed here
It was decided to first start only with the read-only automatic variables because they would always result in a runtime error. Others need to be carefully considered since sometimes assignment can be by design for some of the automatic variables. I am relatively sure that we could add $input to this list though. :-)
Thanks for the feedback
madmidi A function parameter with a read-only automatic variable such as $error does warn, as I said, the $input variable is just not yet part of the list of variables to warn against:
function Demo
{
Param (
[string] $error
)
}
Invoke-ScriptAnalyzer C:\Users\cberg\Desktop\a.ps1
RuleName Severity ScriptName Line Message
-------------------------------------
PSAvoidAssignmentToAutomaticVariabl Error a.ps1 4 The Variable 'error' cannot be assigned since it is a
e readonly automatic variable that is built into PowerShell,
please use a different name.
Activity
bergmeister commentedon Jun 15, 2018
madmidi in PSScriptAnalyzer 1.17.1 there is already a new rule
PSAvoidAssignmentToAutomaticVariablethat catches assignments against the automatic variables listed hereIt was decided to first start only with the read-only automatic variables because they would always result in a runtime error. Others need to be carefully considered since sometimes assignment can be by design for some of the automatic variables. I am relatively sure that we could add
$inputto this list though. :-)Thanks for the feedback
bergmeister commentedon Jun 20, 2018
madmidi A function parameter with a read-only automatic variable such as
$errordoes warn, as I said, the$inputvariable is just not yet part of the list of variables to warn against:sicklittlemonkey commentedon Mar 1, 2021
I did the exact same thing last night. Half an hour of my life wasted, but I suppose at least I know about $input now.
The names for these automatic variables are truly stupid. They should have a differentiator in naming or syntax.
fflaten commentedon Feb 27, 2023
Should be fixed by 5d529a3