Skip to content

AvoidDefaultValueForMandatoryParameter : The rule is not be triggered when the value of the parameter 'Mandatory' is an integer  #877

Closed
@LaurentDardenne

Description

@LaurentDardenne

If, for a parameter attribute, the value of the parameter 'Mandatory' is an integer, the rule will not be triggered:

Invoke-ScriptAnalyzer -ScriptDefinition @'
function Test3
{
    [CmdletBinding()]
    [OutputType([String])]
    param(
        # this one has default value
        [Parameter(Mandatory=1)]
        $Param31="String",

        # this parameter has default value but it is not mandatory
        [Parameter(Mandatory=0)]
        $Param32='Test'
    )
    $Param31
    $Param31 = "test"
}
'@

Even if this writing is not a good practice since the runtime allows it, the rule should be triggered.
Unless to create a rule to handle this type of writing :-)

(Get-Module -Name PSScriptAnalyzer).version.tostring()
#1.16.1

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14409.1012
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14409.1012}
BuildVersion                   10.0.14409.1012
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions