-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Set-StrictMode should detect use of automatic variables as parameters or the target of an assignment #3061
Description
It's common for people to inadvertently to use an automatic variable as a parameter name or a variable name, and then get confused when it doesn't contain the value they expect.
This is just one example but it comes up fairly often, and unless you already know the name is reserved, PowerShell doesn't offer you any clues as to what's going on.
Because the various automatic variables get overwritten based on different conditions, it can be even more confusing when it seems to work in one context but not another.
Given Set-StrictMode's other roles, this seems like a good fit.
One intentional use is for nullification, as in:
$null = Invoke-CommandWithUnwantedOutput
So that could be an exception (because it's unlikely to be done unintentionally), but my thoughts are that there are other ways to achieve this, and strict mode is not enabled by default, so in my opinion it should not be an exception.