Skip to content

PSProvideDefaultParameterValue is always wrong #458

Closed
@Jaykul

Description

@Jaykul

This rule should not exist at all. You agreed with me about this, but it's still in there?

Function parameters are always automatically defined in the local scope and initialized by PowerShell to their default value (the equivalent of null -- which comes out as an empty string or a zero for numerical values, or a default struct, etc)

This happens even when they are part of an unused parameter set.

There is absolutely ZERO value in setting them yourself.

I repeat. There is nothing to be gained by setting them yourself *unless you actually need them to default to something other than $null.

If anything, setting a default value to $null, 0 or an empty string should cause a performance and readability warning. Initializing a variable to it's default value is just extra work; extra code that accomplishes nothing. It might make your script (infinitesimally) slower, and make future editors of your script pause to understand what you're doing ... whilst changing nothing.

NOTE: I ALREADY FILED THIS BUG ONCE. You even agreed with me and supposedly fixed it (to warn when default values are assigned to mandatory parameters), but it is still wrong in v1.4 (See #362)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions