You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
The text was updated successfully, but these errors were encountered:
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:
If I turn on CA with the "All Rules" ruleset:

I get no errors and the only warning I get is that
args
in theMain
method is not used. So I think PSScriptAnalyzer is going way too far in applying this rule to function parameters.The text was updated successfully, but these errors were encountered: