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
Make sure you are able to repro it on the latest released version
Perform a quick search for existing issues to check if this bug has already been reported
Steps to reproduce
Custom rule module:
<#.SYNOPSIS Static methods are not allowed in constrained language mode..DESCRIPTION Static methods are not allowed in constrained language mode. To fix a violation of this rule, use a cmdlet or function instead of a static method..EXAMPLE Test-StaticMethod -CommandAst $CommandAst.INPUTS [System.Management.Automation.Language.ScriptBlockAst].OUTPUTS [PSCustomObject[]].NOTES Reference: Output, CLM info.#>functionTest-StaticMethod
{
[CmdletBinding()]
[OutputType([PSCustomObject[]])]
Param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.Language.ScriptBlockAst]
$ScriptBlockAst
)
Process
{
try
{
# Gets methods$invokedMethods=$ScriptBlockAst.FindAll({$args[0] -is [System.Management.Automation.Language.CommandExpressionAst] -and$args[0].Expression -match"^\[.*\]::" },$true)
foreach ($invokedMethodin$invokedMethods)
{
[PSCustomObject]@{Message=“Avoid Using Static Methods”;
Extent=$invokedMethod.Extent;
RuleName=$PSCmdlet.MyInvocation.InvocationName;
Severity=“Warning”}
}
}
catch
{
$PSCmdlet.ThrowTerminatingError($PSItem)
}
}
}
Before submitting a bug report:
Steps to reproduce
Custom rule module:
Target script:
Script analyzer invocation:
Expected behavior
Actual behavior
The issue lies here:
PSScriptAnalyzer/Engine/ScriptAnalyzer.cs
Lines 1287 to 1292 in 8db488d
When properties are not in the returned object, they surface as null and we need to defend against that.
The text was updated successfully, but these errors were encountered: