Skip to content

Commit

Permalink
Fix method ordering, xmldoc, and remove obsolete XUnit verifiers (#367)
Browse files Browse the repository at this point in the history
* Fix method ordering, xmldoc, and remove obsolete XUnit verifiers

* Address PR comments

* Update Analyzer description
  • Loading branch information
jviau authored Jan 27, 2025
1 parent 2ff37c5 commit e9b42f9
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 63 deletions.
22 changes: 7 additions & 15 deletions src/Analyzers/Analyzers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,22 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IncludeShared>false</IncludeShared>
<IsRoslynComponent>true</IsRoslynComponent>
<EnableStyleCop>true</EnableStyleCop>

<!-- Do not include the generator as a lib dependency -->
<IncludeBuildOutput>false</IncludeBuildOutput>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<IncludeShared>false</IncludeShared>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<!-- Do not publish it until it is ready to release -->
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

<PropertyGroup>
<PackageDescription>.NET Analyzers for the Durable Task Framework.</PackageDescription>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<NoWarn>$(NoWarn);SA0001;</NoWarn>
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>0.0.1</VersionPrefix>
<VersionSuffix>preview.1</VersionSuffix>
<PackageDescription>.NET Analyzers for the Durable Task SDK.</PackageDescription>
<NeutralLanguage>en</NeutralLanguage>
<IncludeBuildOutput>false</IncludeBuildOutput> <!-- Do not include the analyzer as a lib dependency -->
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<IsPackable>false</IsPackable> <!-- Do not publish it until it is ready to release -->
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Analyzers/Orchestration/OrchestrationContextFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.DurableTask.Analyzers.Orchestration;
/// </summary>
/// <param name="semanticModel">The Semantic Model retrieved from the Document.</param>
/// <param name="knownTypeSymbols">Well-known types that are used by the Durable analyzers.</param>
/// <param name="oldRoot">The root Syntax Node retrieved from the Document.</param>
/// <param name="root">The root Syntax Node retrieved from the Document.</param>
/// <param name="syntaxNodeWithDiagnostic">Syntax Node that contains the diagnostic.</param>
/// <param name="taskOrchestrationContextSymbol">The 'TaskOrchestrationContext' symbol.</param>
public readonly struct OrchestrationCodeFixContext(
Expand Down
26 changes: 13 additions & 13 deletions src/Client/AzureManaged/DurableTaskSchedulerClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ public static DurableTaskSchedulerClientOptions FromConnectionString(string conn
return FromConnectionString(new DurableTaskSchedulerConnectionString(connectionString));
}

/// <summary>
/// Creates a new instance of <see cref="DurableTaskSchedulerClientOptions"/> from a parsed connection string.
/// </summary>
/// <param name="connectionString">The connection string to parse.</param>
/// <returns>A new instance of <see cref="DurableTaskSchedulerClientOptions"/>.</returns>
internal static DurableTaskSchedulerClientOptions FromConnectionString(
DurableTaskSchedulerConnectionString connectionString) => new()
{
EndpointAddress = connectionString.Endpoint,
TaskHubName = connectionString.TaskHubName,
Credential = GetCredentialFromConnectionString(connectionString),
};

/// <summary>
/// Creates a gRPC channel for communicating with the Durable Task Scheduler service.
/// </summary>
Expand Down Expand Up @@ -96,19 +109,6 @@ this.Credential is not null
});
}

/// <summary>
/// Creates a new instance of <see cref="DurableTaskSchedulerClientOptions"/> from a parsed connection string.
/// </summary>
/// <param name="connectionString">The connection string to parse.</param>
/// <returns>A new instance of <see cref="DurableTaskSchedulerClientOptions"/>.</returns>
internal static DurableTaskSchedulerClientOptions FromConnectionString(
DurableTaskSchedulerConnectionString connectionString) => new()
{
EndpointAddress = connectionString.Endpoint,
TaskHubName = connectionString.TaskHubName,
Credential = GetCredentialFromConnectionString(connectionString),
};

static TokenCredential? GetCredentialFromConnectionString(DurableTaskSchedulerConnectionString connectionString)
{
string authType = connectionString.Authentication;
Expand Down
26 changes: 13 additions & 13 deletions src/Worker/AzureManaged/DurableTaskSchedulerWorkerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ public static DurableTaskSchedulerWorkerOptions FromConnectionString(string conn
return FromConnectionString(new DurableTaskSchedulerConnectionString(connectionString));
}

/// <summary>
/// Creates a new instance of <see cref="DurableTaskSchedulerWorkerOptions"/> from a parsed connection string.
/// </summary>
/// <param name="connectionString">The connection string to parse.</param>
/// <returns>A new instance of <see cref="DurableTaskSchedulerWorkerOptions"/>.</returns>
internal static DurableTaskSchedulerWorkerOptions FromConnectionString(
DurableTaskSchedulerConnectionString connectionString) => new()
{
EndpointAddress = connectionString.Endpoint,
TaskHubName = connectionString.TaskHubName,
Credential = GetCredentialFromConnectionString(connectionString),
};

/// <summary>
/// Creates a gRPC channel for communicating with the Durable Task Scheduler service.
/// </summary>
Expand Down Expand Up @@ -103,19 +116,6 @@ this.Credential is not null
});
}

/// <summary>
/// Creates a new instance of <see cref="DurableTaskSchedulerWorkerOptions"/> from a parsed connection string.
/// </summary>
/// <param name="connectionString">The connection string to parse.</param>
/// <returns>A new instance of <see cref="DurableTaskSchedulerWorkerOptions"/>.</returns>
internal static DurableTaskSchedulerWorkerOptions FromConnectionString(
DurableTaskSchedulerConnectionString connectionString) => new()
{
EndpointAddress = connectionString.Endpoint,
TaskHubName = connectionString.TaskHubName,
Credential = GetCredentialFromConnectionString(connectionString),
};

static TokenCredential? GetCredentialFromConnectionString(DurableTaskSchedulerConnectionString connectionString)
{
string authType = connectionString.Authentication;
Expand Down
4 changes: 2 additions & 2 deletions test/Analyzers.Tests/Analyzers.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.9.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="1.1.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,13 @@ static DateTime MyRunAsync(TaskOrchestrationContext context)

DiagnosticResult expected = BuildDiagnostic().WithLocation(0).WithArguments("MyRunAsync", "System.DateTime.Now", "MyRun");

await VerifyCS.VerifyDurableTaskCodeFixAsync(code, expected, fix);
await VerifyCS.VerifyDurableTaskCodeFixAsync(code, expected, fix, test =>
{
// By default, the analyzer will fail the test if the analyzer is 'non-local'. We set this behavior to skip
// that check to allow this analyzer to pass, but we should follow up on this as it is a bad practice.
// TODO: Investigate and address non-local analyzer behavior.
test.CodeFixTestBehaviors |= CodeFixTestBehaviors.SkipLocalDiagnosticCheck;
});
}


Expand Down
9 changes: 4 additions & 5 deletions test/Analyzers.Tests/Verifiers/CSharpAnalyzerVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;

namespace Microsoft.DurableTask.Analyzers.Tests.Verifiers;

Expand All @@ -14,15 +13,15 @@ public static partial class CSharpAnalyzerVerifier<TAnalyzer>
{
/// <inheritdoc cref="AnalyzerVerifier{TAnalyzer, TTest, TVerifier}.Diagnostic()"/>
public static DiagnosticResult Diagnostic()
=> CSharpAnalyzerVerifier<TAnalyzer, XUnitVerifier>.Diagnostic();
=> CSharpAnalyzerVerifier<TAnalyzer, DefaultVerifier>.Diagnostic();

/// <inheritdoc cref="AnalyzerVerifier{TAnalyzer, TTest, TVerifier}.Diagnostic(string)"/>
public static DiagnosticResult Diagnostic(string diagnosticId)
=> CSharpAnalyzerVerifier<TAnalyzer, XUnitVerifier>.Diagnostic(diagnosticId);
=> CSharpAnalyzerVerifier<TAnalyzer, DefaultVerifier>.Diagnostic(diagnosticId);

/// <inheritdoc cref="AnalyzerVerifier{TAnalyzer, TTest, TVerifier}.Diagnostic(DiagnosticDescriptor)"/>
public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
=> CSharpAnalyzerVerifier<TAnalyzer, XUnitVerifier>.Diagnostic(descriptor);
=> CSharpAnalyzerVerifier<TAnalyzer, DefaultVerifier>.Diagnostic(descriptor);

/// <inheritdoc cref="AnalyzerVerifier{TAnalyzer, TTest, TVerifier}.VerifyAnalyzerAsync(string, DiagnosticResult[])"/>
public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected)
Expand All @@ -36,7 +35,7 @@ public static async Task VerifyAnalyzerAsync(string source, params DiagnosticRes
await test.RunAsync(CancellationToken.None);
}

public class Test : CSharpAnalyzerTest<TAnalyzer, XUnitVerifier>
public class Test : CSharpAnalyzerTest<TAnalyzer, DefaultVerifier>
{
}
}
14 changes: 9 additions & 5 deletions test/Analyzers.Tests/Verifiers/CSharpCodeFixVerifier.Durable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,30 @@ public static Task VerifyDurableTaskAnalyzerAsync(string source, params Diagnost
return VerifyDurableTaskAnalyzerAsync(source, null, expected);
}

public static async Task VerifyDurableTaskAnalyzerAsync(string source, Action<Test>? configureTest = null, params DiagnosticResult[] expected)
public static async Task VerifyDurableTaskAnalyzerAsync(
string source, Action<Test>? configureTest = null, params DiagnosticResult[] expected)
{
await RunAsync(expected, new Test()
{
TestCode = source,
}, configureTest);
}

public static Task VerifyDurableTaskCodeFixAsync(string source, DiagnosticResult expected, string fixedSource)
public static Task VerifyDurableTaskCodeFixAsync(
string source, DiagnosticResult expected, string fixedSource, Action<Test>? configureTest = null)
{
return VerifyDurableTaskCodeFixAsync(source, [expected], fixedSource);
return VerifyDurableTaskCodeFixAsync(source, [expected], fixedSource, configureTest);
}

public static async Task VerifyDurableTaskCodeFixAsync(string source, DiagnosticResult[] expected, string fixedSource)
public static async Task VerifyDurableTaskCodeFixAsync(
string source, DiagnosticResult[] expected, string fixedSource, Action<Test>? configureTest = null)
{
await RunAsync(expected, new Test()
{
TestCode = source,
FixedCode = fixedSource,
});
},
configureTest);
}

static async Task RunAsync(DiagnosticResult[] expected, Test test, Action<Test>? configureTest = null)
Expand Down
9 changes: 4 additions & 5 deletions test/Analyzers.Tests/Verifiers/CSharpCodeFixVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;

namespace Microsoft.DurableTask.Analyzers.Tests.Verifiers;

Expand All @@ -16,15 +15,15 @@ public static partial class CSharpCodeFixVerifier<TAnalyzer, TCodeFix>
{
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic()"/>
public static DiagnosticResult Diagnostic()
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, XUnitVerifier>.Diagnostic();
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic();

/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic(string)"/>
public static DiagnosticResult Diagnostic(string diagnosticId)
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, XUnitVerifier>.Diagnostic(diagnosticId);
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic(diagnosticId);

/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic(DiagnosticDescriptor)"/>
public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, XUnitVerifier>.Diagnostic(descriptor);
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic(descriptor);

/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.VerifyAnalyzerAsync(string, DiagnosticResult[])"/>
public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected)
Expand Down Expand Up @@ -59,7 +58,7 @@ public static async Task VerifyCodeFixAsync(string source, DiagnosticResult[] ex
await test.RunAsync(CancellationToken.None);
}

public class Test : CSharpCodeFixTest<TAnalyzer, TCodeFix, XUnitVerifier>
public class Test : CSharpCodeFixTest<TAnalyzer, TCodeFix, DefaultVerifier>
{
}
}
2 changes: 1 addition & 1 deletion test/Generators.Tests/Generators.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit" Version="1.1.*" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.9.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.9.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.9.0" PrivateAssets="all" />
Expand Down
3 changes: 1 addition & 2 deletions test/Generators.Tests/Utils/CSharpSourceGeneratorVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;

namespace Microsoft.DurableTask.Generators.Tests.Utils;

// Mostly copy/pasted from the Microsoft Source Generators testing documentation
public static class CSharpSourceGeneratorVerifier<TSourceGenerator> where TSourceGenerator : ISourceGenerator, new()
{
public class Test : CSharpSourceGeneratorTest<TSourceGenerator, XUnitVerifier>
public class Test : CSharpSourceGeneratorTest<TSourceGenerator, DefaultVerifier>
{
public Test()
{
Expand Down

0 comments on commit e9b42f9

Please sign in to comment.