GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||
GeezerVison is showing github.com — Warn on integer ValidateRange bounds for floating-point parameters by Copilot · Pull Request #2267 · PowerShell/PSScriptAnalyzer Conversation
|
There was an error while loading. Please reload this page.
| File | Description |
|---|---|
| Tests/Rules/AvoidValidateRangeTypeMismatch.tests.ps1 | Adds warning and no-warning test cases. |
| Rules/Strings.resx | Adds rule metadata and diagnostic text. |
| Rules/AvoidValidateRangeTypeMismatch.cs | Implements parameter and boundary-type checks. |
| docs/Rules/README.md | Lists the new warning rule. |
| docs/Rules/AvoidValidateRangeTypeMismatch.md | Explains the rule, examples, and suppression options. |
Review effort: Balanced
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
* Initial plan * Fix ValidateRange analyzer review findings Co-authored-by: bergmeister <[email protected]> * Restore decimal range test coverage Co-authored-by: bergmeister <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: bergmeister <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The rule misses static integral constant bounds and incorrectly flags unrelated custom ValidateRange attributes, causing both false negatives and false positives.
In code that hasn't changed since last review
Rules/AvoidValidateRangeTypeMismatch.cs:121
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.
Review effort: Balanced
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
* Initial plan * Handle ValidateRange static integral bounds Co-authored-by: bergmeister <[email protected]> * Fix ValidateRange review edge cases Co-authored-by: bergmeister <[email protected]> * Add real Contoso.ValidateRangeAttribute to test fixture Co-authored-by: bergmeister <[email protected]> * Test non-constant ValidateRange bounds Co-authored-by: bergmeister <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: bergmeister <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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 🎉
In code that hasn't changed since last review
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.
Review effort: Balanced
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Copilot fix |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: bergmeister <[email protected]>
Nullable |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Human assessment is needed because parenthesized integer bounds can bypass the rule’s warning, potentially allowing fractional values outside the declared range.
No open issues 🎉
Review effort: Balanced
Sorry, something went wrong.
There was an error while loading. Please reload this page.
At least 1 approving review is required to merge this pull request.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
ValidateRange boundary type vs parameter type check
There was an error while loading. Please reload this page.