Dynamically count expected rules in GetScriptAnalyzerRule test#2167
Open
andyleejordan wants to merge 1 commit intomainfrom
Open
Dynamically count expected rules in GetScriptAnalyzerRule test#2167andyleejordan wants to merge 1 commit intomainfrom
andyleejordan wants to merge 1 commit intomainfrom
Conversation
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.
Contributor
There was a problem hiding this comment.
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 scanningRules/**/*.csforExport(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.
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 |
Member
Author
There was a problem hiding this comment.
Wow bad Copilot, that suggestion would mean that we don't end up testing anything at all.
Member
Author
There was a problem hiding this comment.
(Claude did the actual PR...lol)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Had Copilot do this:
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.