-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Closed
Closed
Copy link
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or more
Description
Summary of the new feature/enhancement
There are cases where incorrect use of parameter and validation attributes results in them getting quietly ignored, which is undesirable from a UX perspective.
Ideally, such cases would cause errors at parse time (though I don't know if that's feasible), ideally complemented with PSScriptAnalyzer warnings.
If feasible, the changes would technically be breaking; if that's a problem, PSScriptAnalyzer warnings will have to do.
Quietly ignored [Parameter()]
attributes if accidentally used outside param(...)
& {
# Note the missing param(...) enclosure.
[Parameter(ValueFromPipeline)] # quietly ignored
$foo = 'bar' # parsed as a local variable, not as parameter
}
Quietly ignored [Validate*()]
attributes if a variable isn't initialized:
& {
# Missing `= <RHS>`, so the attribute is ignored and the
# value of $foo (if any) is returned
[ValidateRange(1,10)] $foo
}
Pointless combination of [Parameter(Mandatory)]
with a parameter default value:
Note that there's one case where a PSScriptAnalyzer warning alone is probably the right solution - and that warning already exists - given that existing code may still behave as designed (the default value may be a remnant from before a parameter was made mandatory):
& {
param(
[Parameter(Mandatory)]
$foo = 'bar' # pointless, because `Mandatory` still prompts
)
}
vexx32 and KevinMarquette
Metadata
Metadata
Assignees
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or more