Repository navigation
Refactor duplicated class fixture analyzer validation into shared helper - #9492
Merged
Amaury Levé (Evangelink) merged 3 commits intoJun 29, 2026
Merged
Conversation
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor duplicate AnalyzeSymbol methods in fixture analyzers
Refactor duplicated class fixture analyzer validation into shared helper
Jun 29, 2026
Amaury Levé (Evangelink)
marked this pull request as ready for review
June 29, 2026 10:08
Amaury Levé (Evangelink)
enabled auto-merge (squash)
June 29, 2026 10:08
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors MSTest analyzer logic by centralizing class-level fixture method validation ([ClassInitialize] / [ClassCleanup]) into FixtureMethodAnalyzerHelper, reducing duplication and drift risk while keeping the behavior differences explicit via FixtureParameterMode.
Changes:
- Added
RegisterClassFixtureAnalyzer(...)andAnalyzeClassFixtureMethod(...)to consolidate class-fixture analyzer registration and validation. - Updated
ClassInitializeShouldBeValidAnalyzerandClassCleanupShouldBeValidAnalyzerto delegate to the new helper (removing duplicatedAnalyzeSymbollogic).
Show a summary per file
| File | Description |
|---|---|
| src/Analyzers/MSTest.Analyzers/Helpers/FixtureMethodAnalyzerHelper.cs | Adds shared registration + analysis helper for class-level fixtures. |
| src/Analyzers/MSTest.Analyzers/ClassInitializeShouldBeValidAnalyzer.cs | Simplifies analyzer to call the shared class-fixture helper with MustHaveTestContext. |
| src/Analyzers/MSTest.Analyzers/ClassCleanupShouldBeValidAnalyzer.cs | Simplifies analyzer to call the shared class-fixture helper with OptionalTestContext. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Low
Petr Pokorny (0101)
approved these changes
Jun 29, 2026
…e-tribble # Conflicts: # src/Analyzers/MSTest.Analyzers/Helpers/FixtureMethodAnalyzerHelper.cs
Amaury Levé (Evangelink)
approved these changes
Jun 29, 2026
Amaury Levé (Evangelink)
disabled auto-merge
June 29, 2026 13:50
Amaury Levé (Evangelink)
deleted the
copilot/duplicate-code-fix-analyzers
branch
June 29, 2026 13:50
This was referenced Jun 29, 2026
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.
ClassInitializeShouldBeValidAnalyzerandClassCleanupShouldBeValidAnalyzerduplicated near-identical class-fixtureAnalyzeSymbollogic, creating drift risk. This change aligns class-level fixture analyzers with the existing instance-fixture helper pattern and centralizes the shared validation path.Shared class-fixture helper
RegisterClassFixtureAnalyzer(...)toFixtureMethodAnalyzerHelperto standardize analyzer registration for class-level fixture attributes.AnalyzeClassFixtureMethod(...)to hold the common class-fixture signature/type validation logic (including inheritance-mode + abstract/sealed checks).Analyzer simplification
ClassInitializeShouldBeValidAnalyzernow delegates to the helper withFixtureParameterMode.MustHaveTestContext.ClassCleanupShouldBeValidAnalyzernow delegates to the helper withFixtureParameterMode.OptionalTestContext.AnalyzeSymbolmethods from both analyzers.Behavior-preserving parameterization
FixtureParameterMode, while preserving the same diagnostic/fixable behavior.