Skip to content

Commit 144fdad

Browse files
committed
Ignore async Main method
1 parent 382ffee commit 144fdad

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Menees.Analyzers.CodeFixes/Men019SupportAsyncCancellationTokenFixer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
4949

5050
#region Private Methods
5151

52-
[Browsable(true)]
5352
private static async Task<Document> GetTransformedDocumentAsync(
5453
Document document,
5554
Diagnostic diagnostic,
@@ -88,7 +87,7 @@ or SyntaxKind.OutKeyword
8887
.WithAdditionalAnnotations(Formatter.Annotation);
8988

9089
SyntaxNode newSyntaxRoot = syntaxRoot.ReplaceNode(oldParameterList, newParameterList);
91-
return document.WithSyntaxRoot(newSyntaxRoot);
90+
result = document.WithSyntaxRoot(newSyntaxRoot);
9291
}
9392
}
9493

src/Menees.Analyzers/Men019SupportAsyncCancellationToken.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ public void HandleNamedTypeSymbol(SymbolAnalysisContext context)
131131
&& !method.IsOverride
132132
&& method.ExplicitInterfaceImplementations.IsDefaultOrEmpty
133133
&& !IsImplicitInterfaceImplementation(method)
134-
&& !settings.IsUnitTestMethod(method))
134+
&& !settings.IsUnitTestMethod(method)
135+
&& !IsAssemblyEntryPoint(method, ref context))
135136
{
136137
eligibleMethods.Add(method);
137138

@@ -260,6 +261,14 @@ private bool IsImplicitInterfaceImplementation(IMethodSymbol method)
260261
return result;
261262
}
262263

264+
private static bool IsAssemblyEntryPoint(IMethodSymbol method, ref SymbolAnalysisContext context)
265+
{
266+
bool result = method.IsStatic
267+
&& method.Name == "Main"
268+
&& SymbolComparer.Equals(method, context.Compilation.GetEntryPoint(context.CancellationToken));
269+
return result;
270+
}
271+
263272
private bool HasCancellationTokenParameter(List<IParameterSymbol> parameters)
264273
{
265274
bool result = false;

0 commit comments

Comments
 (0)