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
PSProvideDefaultParameterValue is always wrong. #362
Comments
Signed. |
Agree. Will change to rule to warn users if they provide a default value for a Mandatory parameter. |
Be sure to check all parameter sets that parameter belongs to when creating The rule should only warn users when a parameter that is mandatory in every *Kirk Munro * Need a PowerShell SME for a project at work? Contact me On Wed, Nov 18, 2015 at 3:53 PM, Raghu Shantha [MSFT] <
|
Hang on, you're confusing me with #360 My point is that PSProvideDefaultParameterValue is always wrong. There's nothing wrong with providing default values if the parameter is (sometimes) not mandatory, but any rule that makes default values required is wrong. |
Raghu said they would change this rule such that it only warns when default parameter values are assigned to mandatory parameters. I read that as saying that is all this rule would do, and suggested they only do that for parameters that are mandatory in every parameter set in which they are used. Nothing else. No default value checking for optional parameters. Is that not what you meant Raghu? |
Correct. Here is the PR with the change: |
This rule should not exist at all
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, and nothing to be gained in setting them yourself -- unless you actually need them to default to something other than
$null
.If anything, this should be warned against for performance reasons. Initializing a variable to it's default value is just extra work that accomplishes nothing. It might even make your script (infinitesimally) slower, whilst changing nothing.
The text was updated successfully, but these errors were encountered: