Skip to content

Recognize static integral ValidateRange bounds - #2278

Merged
Christoph Bergmeister (bergmeister) merged 5 commits into
copilot/validate-range-boundary-checkfrom
copilot/fix-code-for-review-comments
Oct 28, 2026
Merged

Christoph Bergmeister (bergmeister) merged 5 commits into
copilot/validate-range-boundary-checkfrom
copilot/fix-code-for-review-comments

Conversation

Copilot AI commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

AvoidValidateRangeTypeMismatch missed integral bounds expressed as static constants and could warn for unrelated custom attributes with similar names.

  • Boundary detection: Recognize public static literal integral fields without invoking property getters.
  • Attribute matching: Require the resolved System.Management.Automation.ValidateRangeAttribute type.
param([double][ValidateRange(0, [int]::MaxValue)]$Value)

Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code based on review comments Recognize static integral ValidateRange bounds Oct 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 warnings for inherited public static bounds and fully qualified ValidateRange declarations without the Attribute suffix because its reflection lookups do not support either case.

2 open issues
What changed in this PR

This PR refines AvoidValidateRangeTypeMismatch to recognize static integral constants without invoking property getters and to identify the actual PowerShell validation attribute.

Changes:

  • Detect public static integral constant fields used as range bounds.
  • Replace attribute-name matching with a resolved-type comparison.
  • Add regression cases for [int]::MaxValue and an unrelated attribute name.
File Description
Tests/​Rules/​AvoidValidateRangeTypeMismatch.tests.ps1 Adds constant-bound and unrelated-attribute regression cases.
Rules/​AvoidValidateRangeTypeMismatch.cs Adds constant-field detection and exact attribute-type matching.

Review effort: Balanced

Comment thread Rules/AvoidValidateRangeTypeMismatch.cs Outdated
Comment thread Rules/AvoidValidateRangeTypeMismatch.cs Outdated
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The negative test never loads Contoso.ValidateRangeAttribute, leaving rejection of a successfully resolved custom attribute untested.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread Tests/Rules/AvoidValidateRangeTypeMismatch.tests.ps1
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The member-expression tests lack negative coverage for throwing static getters, static readonly integral fields, and floating-point constants, leaving getter non-execution and literal-integral-only behavior unguarded against regressions.

2 open issues

Review effort: Balanced

Comment thread Rules/AvoidValidateRangeTypeMismatch.cs
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the added static integral constant support and stricter attribute matching.

2 open issues

Review effort: Balanced

@bergmeister

Copy link
Copy Markdown
Collaborator

🟢 Approval recommended

No active review issues are reported for the added static integral constant support and stricter attribute matching.

2 open issues

Review effort: Balanced

Copilot fix the 2 open issues

Copilot AI commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

🟢 Approval recommended

No active review issues are reported for the added static integral constant support and stricter attribute matching.

...

Both open items are already addressed on this branch: the resolved Contoso.ValidateRangeAttribute fixture is in 0fd8633, and the throwing-getter, readonly-integral, and floating-point negative cases are in bd60450. CI passed on the current commit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the changes supporting static integral bounds and excluding unrelated custom attributes.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@bergmeister
Christoph Bergmeister (bergmeister) marked this pull request as ready for review October 28, 2026 15:14
@bergmeister
Christoph Bergmeister (bergmeister) merged commit 919cef7 into copilot/validate-range-boundary-check Oct 28, 2026
10 checks passed
@bergmeister
Christoph Bergmeister (bergmeister) deleted the copilot/fix-code-for-review-comments branch October 28, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants