Skip to content

fix(New-FeatureFlag): $Rules parameter cannot be both Mandatory and have a default value #35

@HeyItsGilbert

Description

@HeyItsGilbert

Summary

$Rules in New-FeatureFlag is declared [Parameter(Mandatory)] and simultaneously initialized to $Rules = @(). PSScriptAnalyzer flags this as PSAvoidDefaultValueForMandatoryParameter. A Mandatory parameter with a default value is a contradiction — PowerShell ignores the default and prompts for input.

Since feature flags are commonly created with no rules initially (rules are added later), Mandatory is almost certainly wrong here.

File

Gatekeeper/Public/New-FeatureFlag.ps1:58-60

Fix

Remove Mandatory from the parameter declaration:

# Before
[Parameter(Mandatory, ValueFromPipeline)]
[Rule[]]
$Rules = @(),

# After
[Parameter(ValueFromPipeline)]
[Rule[]]
$Rules = @(),

Notes

  • Good first issue
  • Found by Brent Tlackburn

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions