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
@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.
I did this recently and needed about 30 minutes to find my bug:
You can pass everything to this parameter, no warning, no error and $input is always $null !
See here, too: #712 "New Rule Suggestion: AvoidReuseOfAutomaticVariables"
The text was updated successfully, but these errors were encountered: