Skip to content

Commit 7c7e640

Browse files
authored
Analyzer: Excluded non-Function methods from BindingAnalyzer (#2244)
1 parent 2283fe8 commit 7c7e640

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

release_notes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77

88
## Dependencies
99
- DurableTask.Core --> v2.10.*
10-
- DurableTask.AzureStorage --> v1.12.*
10+
- DurableTask.AzureStorage --> v1.12.*
11+
- DurableTask.Analyzers --> 0.5.0

src/WebJobs.Extensions.DurableTask.Analyzers/Analyzers/Orchestrator/BindingAnalyzer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using System.Collections.Generic;
45
using System.Linq;
56
using Microsoft.CodeAnalysis;
67
using Microsoft.CodeAnalysis.CSharp;
@@ -21,10 +22,15 @@ public class BindingAnalyzer
2122

2223
public static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, Severity, isEnabledByDefault: true);
2324

24-
public static bool RegisterDiagnostic(CompilationAnalysisContext context, SyntaxNode method)
25+
public static bool RegisterDiagnostic(CompilationAnalysisContext context, SemanticModel semanticModel, SyntaxNode method)
2526
{
2627
var diagnosedIssue = false;
2728

29+
if (!SyntaxNodeUtils.IsInsideFunction(semanticModel, method))
30+
{
31+
return diagnosedIssue;
32+
}
33+
2834
var parameterList = method.ChildNodes().First(x => x.IsKind(SyntaxKind.ParameterList));
2935

3036
foreach (SyntaxNode descendant in parameterList.DescendantNodes())

src/WebJobs.Extensions.DurableTask.Analyzers/Analyzers/Orchestrator/DeterministicMethodAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private void RegisterAnalyzers(CompilationAnalysisContext context)
6666
| ThreadTaskAnalyzer.RegisterDiagnostic(context, semanticModel, methodDeclaration)
6767
| TimerAnalyzer.RegisterDiagnostic(context, semanticModel, methodDeclaration)
6868
| CancellationTokenAnalyzer.RegisterDiagnostic(context, methodDeclaration)
69-
| BindingAnalyzer.RegisterDiagnostic(context, methodDeclaration)
69+
| BindingAnalyzer.RegisterDiagnostic(context, semanticModel, methodDeclaration)
7070
| DependencyInjectionAnalyzer.RegisterDiagnostic(context, methodDeclaration))
7171
{
7272
methodInvocationAnalyzer.RegisterDiagnostics(context, methodInformation);

test/WebJobs.Extensions.DurableTask.Analyzers.Test/Orchestrator/BindingAnalyzerTersts.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public static class HelloSequence
3030
[FunctionName(""BindingAnalyzerTestCases"")]
3131
public static async Task Run(
3232
[OrchestrationTrigger] IDurableOrchestrationContext context)
33+
{
34+
ExcludeNonFunctionsTest(""test"");
35+
}
36+
37+
public void ExcludeNonFunctionsTest([NotNull] string input)
3338
{
3439
}
3540
}

0 commit comments

Comments
 (0)