Add DoNotUseThreadSleepAnalyzer to warn against Thread.Sleep in async…#304
Merged
SergeyTeplyakov merged 1 commit intomasterfrom Jun 29, 2025
Merged
Add DoNotUseThreadSleepAnalyzer to warn against Thread.Sleep in async…#304SergeyTeplyakov merged 1 commit intomasterfrom
SergeyTeplyakov merged 1 commit intomasterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new analyzer to flag uses of Thread.Sleep inside asynchronous contexts.
- Adds a diagnostic descriptor (
EPC33) toDiagnosticDescriptors - Implements
DoNotUseThreadSleepAnalyzerand supporting extension methods - Updates tests and release notes for the new rule
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/ErrorProne.NET.CoreAnalyzers/DiagnosticDescriptors.cs | Declares a new EPC33 descriptor for banning Thread.Sleep in async methods |
| src/ErrorProne.NET.CoreAnalyzers/CompilationExtensions.cs | Adds FindEnclosingMethodSymbol and FindParentLocalOrLambdaSymbol extensions |
| src/ErrorProne.NET.CoreAnalyzers/AsyncAnalyzers/DoNotUseThreadSleepAnalyzer.cs | Implements the analyzer logic and registers the rule |
| src/ErrorProne.NET.CoreAnalyzers/AnalyzerReleases.Unshipped.md | Documents the new EPC33 entry in release notes |
| src/ErrorProne.NET.CoreAnalyzers.Tests/AsyncAnalyzers/DoNotUseThreadSleepAnalyzerTests.cs | Adds comprehensive tests covering async methods, lambdas, and local functions |
Comments suppressed due to low confidence (1)
src/ErrorProne.NET.CoreAnalyzers/AsyncAnalyzers/DoNotUseThreadSleepAnalyzer.cs:19
- The collection expression '[Rule]' does not correctly initialize an ImmutableArray. Use ImmutableArray.Create(Rule) or ImmutableArray.CreateRange(new[] { Rule }) instead.
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => [Rule];
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.
… methods