GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Warn on integer ValidateRange bounds for floating-point parameters by Copilot · Pull Request #2267 · PowerShell/PSScriptAnalyzer

Conversation

Copilot AI commented Oct 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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 range
param([double][ValidateRange(0, 100)]$Value)

# Use floating-point bounds
param([double][ValidateRange(0.0, 100.0)]$Value)
  • Fixes ValidateRange boundary type vs parameter type check #2199

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Initial plan
4fee79e
Copilot AI assigned Copilot and Christoph Bergmeister (bergmeister) Oct 27, 2026
Copilot started work on behalf of Christoph Bergmeister (bergmeister) October 27, 2026 22:32
View session
Copilot AI linked an issue Oct 27, 2026 that may be closed by this pull request
ValidateRange boundary type vs parameter type check #2199
Open
@bergmeister
Add ValidateRange boundary type mismatch rule
7cdaee3
Co-authored-by: bergmeister <[email protected]>
Copilot AI changed the title [WIP] Add type check for ValidateRange boundaries Warn on integer ValidateRange bounds for floating-point parameters Oct 27, 2026
Copilot finished work on behalf of Christoph Bergmeister (bergmeister) October 27, 2026 22:41
Copilot AI requested a review from Christoph Bergmeister (bergmeister) October 27, 2026 22:41
@bergmeister
Christoph Bergmeister (bergmeister) requested a balanced review from Copilot October 28, 2026 11:35
Copilot started reviewing on behalf of Christoph Bergmeister (bergmeister) October 28, 2026 11:35
View session
Copilot AI reviewed Oct 28, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The rule misses affected array parameters and integral-cast bounds while incorrectly warning on mixed integer/floating-point bounds.

3 open issues
  • Medium severity Handle array element types in ValidateRange checks · New
  • Medium severity Avoid false positives for mixed numeric ValidateRange bounds · New
  • Medium severity Classify ValidateRange casts by resolved target type · New
What changed in this PR

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.
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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Rules/AvoidValidateRangeTypeMismatch.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Rules/AvoidValidateRangeTypeMismatch.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Rules/AvoidValidateRangeTypeMismatch.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bergmeister
Christoph Bergmeister (bergmeister) added this pull request to stack #2274 October 28, 2026 11:58
Copilot AI mentioned this pull request Oct 28, 2026
Handle arrays and casts in ValidateRange type-mismatch warnings #2273
Merged
@bergmeister
Christoph Bergmeister (bergmeister) removed this pull request from stack #2274 October 28, 2026 12:11
@bergmeister
Christoph Bergmeister (bergmeister) added this pull request to stack #2277 October 28, 2026 12:24
@bergmeister
Christoph Bergmeister (bergmeister) removed this pull request from stack #2277 October 28, 2026 12:31
@bergmeister
Handle arrays and casts in ValidateRange type-mismatch warnings (#2273)
117fa6b
* 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]>
@bergmeister
Christoph Bergmeister (bergmeister) requested a balanced review from Copilot October 28, 2026 13:13
Copilot started reviewing on behalf of Christoph Bergmeister (bergmeister) October 28, 2026 13:13
View session
Copilot AI reviewed Oct 28, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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.

1 open issue
  • Medium severity Handle static integral constants in ValidateRange bounds · New
1 previously missed issue

In code that hasn't changed since last review

Medium severity Match the resolved ValidateRangeAttribute type

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.

3 resolved since last review
  • Medium severity Classify ValidateRange casts by resolved target type
  • Medium severity Avoid false positives for mixed numeric ValidateRange bounds
  • Medium severity Handle array element types in ValidateRange checks

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Rules/AvoidValidateRangeTypeMismatch.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bergmeister
Christoph Bergmeister (bergmeister) added this pull request to stack #2279 October 28, 2026 13:20
Copilot AI mentioned this pull request Oct 28, 2026
Recognize static integral ValidateRange bounds #2278
Merged
@bergmeister
Christoph Bergmeister (bergmeister) removed this pull request from stack #2279 October 28, 2026 15:14
@bergmeister
Recognize static integral ValidateRange bounds (#2278)
919cef7
* 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]>
@bergmeister
Christoph Bergmeister (bergmeister) requested a balanced review from Copilot October 28, 2026 15:17
Copilot started reviewing on behalf of Christoph Bergmeister (bergmeister) October 28, 2026 15:18
View session
Copilot AI reviewed Oct 28, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Medium severity 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.

1 resolved since last review
  • Medium severity Handle static integral constants in ValidateRange bounds

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bergmeister

Christoph Bergmeister (bergmeister) commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

🔵 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

Medium severity 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.

1 resolved since last review

  • Medium severity Handle static integral constants in ValidateRange bounds

Review effort: Balanced

Copilot fix

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Copilot started work on behalf of Christoph Bergmeister (bergmeister) October 28, 2026 15:23
View session
@bergmeister
Handle nullable ValidateRange parameter types
32bcb67
Co-authored-by: bergmeister <[email protected]>

Copilot AI commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

🔵 Needs a closer look

The rule skips nullable floating-point parameters, leaving fractional values outside integer ValidateRange bounds undetected; nullable types need unwrapping and cover...

Nullable double, single, and decimal parameter types are now unwrapped before checking; regression tests pass. Fixed in 32bcb67.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Copilot finished work on behalf of Christoph Bergmeister (bergmeister) October 28, 2026 15:30
@bergmeister
Christoph Bergmeister (bergmeister) requested a balanced review from Copilot October 28, 2026 15:57
Copilot started reviewing on behalf of Christoph Bergmeister (bergmeister) October 28, 2026 15:57
View session
Copilot AI reviewed Oct 28, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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.

No open issues 🎉

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bergmeister
Christoph Bergmeister (bergmeister) marked this pull request as ready for review October 28, 2026 16:05
@bergmeister
Christoph Bergmeister (bergmeister) requested review from a team and Mikey Lombardi (He/Him) (michaeltlombardi) as code owners October 28, 2026 16:05
@bergmeister Christoph Bergmeister (bergmeister) added the Issue - New Rule label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@bergmeister Christoph Bergmeister (bergmeister) Awaiting requested review from bergmeister bergmeister is a code owner
@michaeltlombardi Mikey Lombardi (He/Him) (michaeltlombardi) Awaiting requested review from michaeltlombardi michaeltlombardi is a code owner

At least 1 approving review is required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@bergmeister Christoph Bergmeister (bergmeister)

Copilot code review Copilot

Labels

Issue - New Rule

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

ValidateRange boundary type vs parameter type check

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@bergmeister
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.