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
{{ message }}
Repository navigation
Warn on integer ValidateRange bounds for floating-point parameters - #2267
Integer ValidateRange bounds can allow fractional values outside the declared range on double, single, and decimal parameters.
Analyzer rule: Add an always-enabled warning for integral bounds on these parameter types.
Coverage and docs: Add focused tests and document the rule.
# Warning: integer bounds can allow fractional values outside the rangeparam([double][ValidateRange(0,100)]$Value)
# Use floating-point boundsparam([double][ValidateRange(0.0,100.0)]$Value)
CopilotAI
changed the title
[WIP] Add type check for ValidateRange boundaries
Warn on integer ValidateRange bounds for floating-point parameters
Oct 27, 2026
Adds a built-in PSScriptAnalyzer warning for integer ValidateRange bounds on floating-point and decimal parameters, addressing the boundary-validation concern in #2199.
Changes:
Introduces the always-enabled PSAvoidValidateRangeTypeMismatch warning and diagnostic messages.
Adds tests for supported parameter types, boundary literals, and qualified attribute names.
Documents the rule with examples and adds it to the rule index.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The rule misses static integral constant bounds and incorrectly flags unrelated custom ValidateRange attributes, causing both false negatives and false positives.
Discarding the namespace also matches unrelated custom attributes. For example, [Contoso.ValidateRange(0, 100)] on a double parameter triggers this warning even when that attribute is not PowerShell's range validator and has different semantics. Compare the resolved attribute type with System.Management.Automation.ValidateRangeAttribute instead; this supports both short and fully qualified built-in names without reporting unrelated attributes.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The rule skips nullable floating-point parameters, leaving fractional values outside integer ValidateRange bounds undetected; nullable types need unwrapping and coverage for double, single, and decimal parameters.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Handle nullable floating-point parameters in range validation
Rules/AvoidValidateRangeTypeMismatch.cs:71
Nullable floating-point parameters are skipped here: param([Nullable[double]][ValidateRange(0, 100)]$Value) resolves to Nullable<double>, which is not in this set. A non-null nullable value is boxed as its underlying numeric type, so integer bounds still permit out-of-range fractional values. Unwrap nullable types before this check and add coverage for nullable double, single, and decimal parameters.
The rule skips nullable floating-point parameters, leaving fractional values outside integer ValidateRange bounds undetected; nullable types need unwrapping and coverage for double, single, and decimal parameters.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Handle nullable floating-point parameters in range validation Rules/AvoidValidateRangeTypeMismatch.cs:71
Nullable floating-point parameters are skipped here: param([Nullable[double]][ValidateRange(0, 100)]$Value) resolves to Nullable<double>, which is not in this set. A non-null nullable value is boxed as its underlying numeric type, so integer bounds still permit out-of-range fractional values. Unwrap nullable types before this check and add coverage for nullable double, single, and decimal parameters.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because parenthesized integer bounds can bypass the rule’s warning, potentially allowing fractional values outside the declared range.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Integer
ValidateRangebounds can allow fractional values outside the declared range ondouble,single, anddecimalparameters.