Refactor fixture signature code fixers to shared base class#8875
Merged
Conversation
7 tasks
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor duplicate code in MSTest.Analyzers.CodeFixes
Refactor fixture signature code fixers to shared base class
Jun 6, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the MSTest fixture-method signature code fix providers in MSTest.Analyzers.CodeFixes by extracting the shared “fix signature” code-fix workflow into a new base class, reducing duplication across the six near-identical fixers.
Changes:
- Added
FixtureMethodSignatureFixerBaseto centralizeFixableDiagnosticIds,GetFixAllProvider(), andRegisterCodeFixesAsync(...). - Updated the six fixture signature fixers to inherit from the base class and provide only rule-specific configuration (
DiagnosticRuleId,IsParameterLess,ShouldBeStatic). - Preserved MEF export behavior (
[ExportCodeFixProvider]and[Shared]) on each concrete fixer type.
Show a summary per file
| File | Description |
|---|---|
| src/Analyzers/MSTest.Analyzers.CodeFixes/Helpers/FixtureMethodSignatureFixerBase.cs | New shared base implementing the common code-fix registration and “fix signature” action creation. |
| src/Analyzers/MSTest.Analyzers.CodeFixes/TestInitializeShouldBeValidFixer.cs | Refactored to inherit from the shared base and provide rule-specific flags. |
| src/Analyzers/MSTest.Analyzers.CodeFixes/TestCleanupShouldBeValidFixer.cs | Refactored to inherit from the shared base and provide rule-specific flags. |
| src/Analyzers/MSTest.Analyzers.CodeFixes/ClassInitializeShouldBeValidFixer.cs | Refactored to inherit from the shared base and provide rule-specific flags. |
| src/Analyzers/MSTest.Analyzers.CodeFixes/ClassCleanupShouldBeValidFixer.cs | Refactored to inherit from the shared base and provide rule-specific flags. |
| src/Analyzers/MSTest.Analyzers.CodeFixes/AssemblyInitializeShouldBeValidFixer.cs | Refactored to inherit from the shared base and provide rule-specific flags. |
| src/Analyzers/MSTest.Analyzers.CodeFixes/AssemblyCleanupShouldBeValidFixer.cs | Refactored to inherit from the shared base and provide rule-specific flags. |
Copilot's findings
- Files reviewed: 7/7 changed files
- Comments generated: 1
Evangelink
approved these changes
Jun 7, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Six fixture-method code fixers in
MSTest.Analyzers.CodeFixeshad near-identical implementations, differing only by diagnostic ID and signature flags. This change centralizes shared behavior to remove lock-step duplication and reduce maintenance risk.What changed
FixtureMethodSignatureFixerBaseinsrc/Analyzers/MSTest.Analyzers.CodeFixes/Helpers/.FixableDiagnosticIdsGetFixAllProvider()RegisterCodeFixesAsync(...)DiagnosticRuleIdIsParameterLessShouldBeStaticRefactored fixers
AssemblyCleanupShouldBeValidFixerAssemblyInitializeShouldBeValidFixerClassCleanupShouldBeValidFixerClassInitializeShouldBeValidFixerTestCleanupShouldBeValidFixerTestInitializeShouldBeValidFixerMEF/export behavior
[ExportCodeFixProvider(...)]and[Shared]on each concrete fixer type.