Skip to content

Rule UseSyntacticallyCorrectExamples fails if parameter uses type that is not loaded #8

@johlju

Description

@johlju

If the rule is testing a function hat has a parameter with a type that is not loaded into the session the rule fails on all parameters in all examples.

For example if having this parameter:

param
(
    [Parameter()]
    [Microsoft.SqlServer.Management.Smo.Server]
    $SqlServerObject
)

This row will return the function but the property Parameters will be $null

which result in that this evaluation always return $true

$_ -is [CommandParameterAst] -and $_.ParameterName -notin $functionInfo.Parameters.Keys

Suggest adding a error message when $null -eq $functionInfo.Parameters saying something like "Parameters of the function X could not be parsed, this can for example be due to that a type that is used by a parameter is not loaded into the session.".

I worked around this by loading stubs classes before running Invoke-ScriptAnalyzer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions