Open
Description
In order to reduce the number of hard to debug errors, we run our PowerShell scripts with Set-StrictMode -Version Latest. This lets us catch issues where we e.g. have misspelled a variable name (or forgot to assign it before using it) during runtime. But it would be immensely useful to catch these kinds of errors before we run the scripts, e.g. during an automated build.
We have deployment scripts that run for quite a long time (several hours), and silly misspelled variable names or misplaced variable assignments then costs quite a bit of development time. Catching these errors early would be immensely useful.
Example of something that should cause an error:
function Get-Foobar()
{
if ($b + 2 -gt 5)
{
return $b
}
return 5
}
This would be OK:
function Get-Foobar($b)
{
if ($b + 2 -gt 5)
{
return $b
}
return 5
}
As would this:
function Get-Foobar()
{
$b = 123;
if ($b + 2 -gt 5)
{
return $b
}
return 5
}