Open iRon7 opened 4 months ago
I did a number of improvements to my prototype but in fact the scope of the rule could be even more wider and might also applied to (incorrect) statements like:
Get-Date - $StartTime
Get-Date: Cannot bind parameter 'Date'. Cannot convert value "-" to type "System.DateTime". Error: "String '-' was not recognized as a valid DateTime."
Although it would already generate a clear error during run time, it would be nice to get the message and suggested correction during design time:
(Get-Date) - $StartTime
PowerShell has two parsing modes:
It is not always clear whenever PowerShell is in argument mode, as in:
For background information, see: Call operator (
&{}
) with no results doesn't type compare#24054
Yet from the argument name (and position and the operators) you could make a reasonable assumption that it probably concerns an operator instead.
For a (PowerShell based) rule prototype, see: https://github.com/iRon7/PSRules/blob/main/PossibleArgumentWithOperatorConfusion.psm1