Closed iRon7 closed 1 year ago
The rule is quite simple and goes through all attributes and if it finds a mandatory attribute, it gives the warning https://github.com/PowerShell/PSScriptAnalyzer/blob/8826d1cab3a39af3e03b413b858bc3a9a22753c0/Rules/AvoidDefaultValueForMandatoryParameter.cs#L50-L61 However, I don't think PSSA should do analysis of parameter sets not just because it can get complicated to reach the correct logic conclusion but also b) the rule principle still applies that defaults for mandatory parameters do not make sense. It is therefore up to you as an author to decide whether a) you remove the default or b) you decide to suppress because it's worthwhile to you keeping a default because of the other parameter set. Therefore I'd say this by design that the author should review the warning and decide what to do with it.
Noted
Steps to reproduce
.\Test.ps1
contains:Expected behavior
No analyzer warnings (The rule should only apply when the parameter is mandatory in all parameter sets)
Actual behavior
If an unexpected error was thrown then please report the full error details using e.g.
$error[0] | Select-Object *
Environment data
The funny part is that no issues are found when the
Test
function is supplied as a script: