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 — Dynamically count expected rules in GetScriptAnalyzerRule test by andyleejordan · Pull Request #2167 · PowerShell/PSScriptAnalyzer

Conversation

@andyleejordan

@andyleejordan Andy Jordan (andyleejordan) commented Mar 18, 2026

Copy link
Copy Markdown
Member

Had Copilot do this:

Replace hardcoded rule count with dynamic counting of [Export(typeof(I...Rule))] attributes in C# source files. This prevents the test from breaking every time a new rule is added.

Seems like it works. I noticed every time a PR that added a rule was merged, all PRs after it failed because this test had a hardcoded assumption.

Sorry, something went wrong.

Uh oh!

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

liamjpeters reacted with hooray emoji
All reactions
  • 🎉 1 reaction
@andyleejordan
Dynamically count expected rules in GetScriptAnalyzerRule test
15bda77
Replace hardcoded rule count with dynamic counting of [Export(typeof(I...Rule))]
attributes in C# source files. This prevents the test from breaking every time a
new rule is added.
Copilot AI review requested due to automatic review settings March 18, 2026 01:24
@andyleejordan
Andy Jordan (andyleejordan) requested review from a team and Christoph Bergmeister (bergmeister) as code owners March 18, 2026 01:24
Copilot started reviewing on behalf of Andy Jordan (andyleejordan) March 18, 2026 01:26
View session
Copilot AI reviewed Mar 18, 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.

Pull request overview

Updates the Get-ScriptAnalyzerRule Pester test to avoid hardcoding the expected number of built-in rules by deriving the expected count dynamically from the repository’s C# rule sources.

Changes:

  • Replaces the fixed expected rule count (72) with a dynamic count based on scanning Rules/**/*.cs for Export(typeof(I*Rule)) occurrences.
  • Adds comments explaining the dynamic rule-counting approach.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Tests/Engine/GetScriptAnalyzerRule.tests.ps1
Comment on lines +66 to +71
# Dynamically count the expected number of rules from source files
# by finding all C# files with [Export(typeof(I...Rule))] attributes
$rulesRoot = Resolve-Path "$PSScriptRoot/../../Rules"
$expectedNumRules = (Get-ChildItem -Path $rulesRoot -Filter '*.cs' -Recurse |
Select-String -Pattern 'Export\(typeof\s*\(I\w+Rule\)\)' |
Select-Object -ExpandProperty Path -Unique).Count

@andyleejordan Andy Jordan (andyleejordan) Mar 18, 2026

Copy link
Copy Markdown
Member Author

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.

Wow bad Copilot, that suggestion would mean that we don't end up testing anything at all.

Sorry, something went wrong.

Uh oh!

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

All reactions

@andyleejordan Andy Jordan (andyleejordan) Mar 18, 2026

Copy link
Copy Markdown
Member Author

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.

(Claude did the actual PR...lol)

Sorry, something went wrong.

Uh oh!

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

All reactions
@andyleejordan
Andy Jordan (andyleejordan) enabled auto-merge (squash) March 18, 2026 01:32
SeeminglyScience
Patrick Meinecke (SeeminglyScience) approved these changes Mar 18, 2026
View reviewed changes
@andyleejordan
Andy Jordan (andyleejordan) merged commit f3e9134 into main Mar 18, 2026
11 checks passed

Uh oh!

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

@andyleejordan
Andy Jordan (andyleejordan) deleted the fix-dynamic-rule-count branch March 18, 2026 17:04
bergmeister
Christoph Bergmeister (bergmeister) reviewed Mar 18, 2026
View reviewed changes

@bergmeister Christoph Bergmeister (bergmeister) left a comment

Copy link
Copy Markdown
Collaborator

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.

Nice addition but it can still be of value to keep a hard=coded check (in addition to this), how about we make it less troublesome by just asserting greater than instead of equals so this test doesn't need updating for every new rule?

Sorry, something went wrong.

Uh oh!

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

All reactions
@iRon7 iRon7 mentioned this pull request Apr 15, 2026
Rule request: Avoid reserved words for functions names #2099
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bergmeister Christoph Bergmeister (bergmeister) bergmeister left review comments
Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@SeeminglyScience Patrick Meinecke (SeeminglyScience) SeeminglyScience approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

4 participants

@andyleejordan @bergmeister @SeeminglyScience
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.