feat: Add PH2161 analyzer to avoid [Retry] attribute and RetryBaseAttribute derivatives#977
Draft
feat: Add PH2161 analyzer to avoid [Retry] attribute and RetryBaseAttribute derivatives#977
Conversation
Co-authored-by: bcollamore <57269455+bcollamore@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Avoid [Retry] attribute
feat: Add PH2159 analyzer to avoid [Retry] attribute and RetryBaseAttribute derivatives
Sep 6, 2025
Brian Collamore (bcollamore)
requested changes
Sep 7, 2025
| AvoidUnusedToString = 2153, | ||
| AvoidUnlicensedPackages = 2155, | ||
| AvoidPkcsPaddingWithRsaEncryption = 2158, | ||
| AvoidRetryAttribute = 2159, |
There was a problem hiding this comment.
Let's switch to 2161. (Another PR has claimed 2159 and 2160). We'll need to update our PH2159.md file name and contents as well.
Contributor
Author
There was a problem hiding this comment.
Updated to use PH2161 as requested. Changed the diagnostic ID in DiagnosticId.cs and AvoidAttributeAnalyzer.cs, renamed the documentation file from PH2159.md to PH2161.md, and updated all references. All 2013 tests pass. (commit 5d8c238)
|
Member
|
Copilot see comments above |
Co-authored-by: bcollamore <57269455+bcollamore@users.noreply.github.com>
Contributor
Author
Copilot
AI
changed the title
feat: Add PH2159 analyzer to avoid [Retry] attribute and RetryBaseAttribute derivatives
feat: Add PH2161 analyzer to avoid [Retry] attribute and RetryBaseAttribute derivatives
Sep 7, 2025
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.



This PR implements a new analyzer PH2161 that detects and prevents the use of MSTest's
[Retry]attribute and any custom attributes that derive fromRetryBaseAttribute.Problem
MSTest provides a
[Retry]attribute to automatically retry flaky tests, but this approach masks underlying issues rather than fixing them. As stated in the issue, "it would be preferable to avoid the flaky test" rather than attempting to overcome it with retries.Solution
The new analyzer detects two scenarios:
[Retry]attribute:RetryBaseAttribute:Implementation Details
The implementation extends the existing
AvoidAttributeAnalyzerwith:RetryBaseAttributeTesting
Added comprehensive test coverage including:
[Retry]attribute usage detectionRetryBaseAttributedetectionDocumentation
Created complete documentation at
Documentation/Diagnostics/PH2161.mdfollowing the established pattern, including examples and guidance on how to resolve violations.Fixes #976.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.