Skip to content

PSProviderDefaultParameterValue should not be applied to parameters #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rkeithhill opened this issue Dec 1, 2015 · 1 comment
Closed

Comments

@rkeithhill
Copy link
Contributor

I'll try to make my case for this again. The function body does not need to provide values for its parameters. That is the job of the caller. The scripter does need to make sure that values are provided and if not, handle that situation appropriately. This could include generating an error (either terminating or not-terminating) or proceeding on with a default value. The scripter can also use PowerShell Validation attributes to help. From what I'm seeing, the analyzer does not take into account these validation attributes e.g. ValidateNotNull. And even if it did, I might be working with an API where $null is a valid value i.e. is a sentinel value.

Finally, even C# and FxCop, do not require a method's parameters to be set to a default value. This C# code:

class Program
{
    static void Main(string[] args)
    {
        Foo("foo");
    }

    static void Foo(string name)
    {
        Console.WriteLine(name);
    }
}

If I turn on CA with the "All Rules" ruleset:
allrules
I get no errors and the only warning I get is that args in the Main method is not used. So I think PSScriptAnalyzer is going way too far in applying this rule to function parameters.

@raghushantha
Copy link
Member

Hi Keith.

We have reworked this rule:
pls see:
#382

The rule (renamed) is fired only when default values are supplied for Mandatory parameters

-Raghu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants