Skip to content

Commit a8842cc

Browse files
authored
Disable ASP0018 in generated EndpointExtensions code (#59)
1 parent 2fb60d2 commit a8842cc

File tree

44 files changed

+183
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+183
-5
lines changed

src/IeuanWalker.MinimalApi.Endpoints.Generator/EndpointGenerator.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
5757
// Extract type information during syntax analysis
5858
IncrementalValuesProvider<TypeInfo?> typeInfos = context.SyntaxProvider
5959
.CreateSyntaxProvider(
60-
predicate: static (s, _) => s is TypeDeclarationSyntax tds && tds.BaseList != null,
60+
predicate: static (s, _) => s is TypeDeclarationSyntax tds && tds.BaseList is not null,
6161
transform: static (ctx, ct) => ExtractTypeInfo(ctx, ct))
62-
.Where(static typeInfo => typeInfo != null);
62+
.Where(static typeInfo => typeInfo is not null);
6363

6464
// Collect all type information
6565
IncrementalValueProvider<ImmutableArray<TypeInfo?>> collectedTypeInfos = typeInfos.Collect();
@@ -105,7 +105,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
105105
{
106106
ITypeSymbol? validatedType = typeSymbol.GetValidatedTypeFromValidator(validatorSymbol);
107107
string? validatedTypeName = validatedType?.ToDisplayString();
108-
if (validatedTypeName != null)
108+
if (validatedTypeName is not null)
109109
{
110110
return new ValidatorInfo(typeName, validatedTypeName, location, [.. diagnostics]);
111111
}
@@ -118,7 +118,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
118118
{
119119
ITypeSymbol? validatedType = typeSymbol.GetValidatedTypeFromValidator(abstractValidatorSymbol);
120120
string? validatedTypeName = validatedType?.ToDisplayString();
121-
if (validatedTypeName != null)
121+
if (validatedTypeName is not null)
122122
{
123123
return new AbstractValidatorInfo(typeName, validatedTypeName, location, [.. diagnostics]);
124124
}
@@ -265,7 +265,7 @@ static void Execute(ImmutableArray<TypeInfo?> typeInfos, string assemblyName, So
265265
// Check if abstract validators match a request type
266266
foreach (AbstractValidatorInfo abstractValidator in allAbstractValidators)
267267
{
268-
bool matchesRequestType = allEndpoints.Any(e => e.RequestType != null && e.RequestType.Equals(abstractValidator.ValidatedTypeName));
268+
bool matchesRequestType = allEndpoints.Any(e => e.RequestType is not null && e.RequestType.Equals(abstractValidator.ValidatedTypeName));
269269
if (matchesRequestType)
270270
{
271271
context.ReportDiagnostic(Diagnostic.Create(
@@ -312,8 +312,11 @@ static string GenerateEndpointExtensions(List<EndpointInfo> endpointClasses, Lis
312312

313313
builder.AppendEmptyLine();
314314
builder.AppendLine($"namespace {assemblyName};");
315+
315316
builder.AppendEmptyLine();
317+
builder.AppendLine("#pragma warning disable ASP0018 // Disable specific ASP.NET analyzer that warns about unused route parameters in generated handlers");
316318

319+
builder.AppendEmptyLine();
317320
builder.AppendLine("public static class EndpointExtensions");
318321
using (builder.AppendBlock())
319322
{
@@ -422,6 +425,9 @@ static string GenerateEndpointExtensions(List<EndpointInfo> endpointClasses, Lis
422425
}
423426
}
424427

428+
builder.AppendEmptyLine();
429+
builder.AppendLine("#pragma warning restore ASP0018");
430+
425431
return builder.ToString();
426432
}
427433

tests/IeuanWalker.MinimalApi.Endpoints.Generator.Tests/Snapshots/DiagnosticSnapshotTests.DiagnosticMINAPI003_GroupConfigureMissingMapGroup_ShouldError#EndpointExtensions.g.verified.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace TestAssembly;
1515

16+
#pragma warning disable ASP0018 // Disable specific ASP.NET analyzer that warns about unused route parameters in generated handlers
17+
1618
public static class EndpointExtensions
1719
{
1820
public static IHostApplicationBuilder AddEndpoints(this IHostApplicationBuilder builder) => builder.AddEndpointsFromTestAssembly();
@@ -40,3 +42,5 @@ public static WebApplication MapEndpointsFromTestAssembly(this WebApplication ap
4042
return app;
4143
}
4244
}
45+
46+
#pragma warning restore ASP0018

tests/IeuanWalker.MinimalApi.Endpoints.Generator.Tests/Snapshots/DiagnosticSnapshotTests.DiagnosticMINAPI004_MultipleMapGroupCallsInGroupConfigure_ShouldError#EndpointExtensions.g.verified.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace TestAssembly;
1515

16+
#pragma warning disable ASP0018 // Disable specific ASP.NET analyzer that warns about unused route parameters in generated handlers
17+
1618
public static class EndpointExtensions
1719
{
1820
public static IHostApplicationBuilder AddEndpoints(this IHostApplicationBuilder builder) => builder.AddEndpointsFromTestAssembly();
@@ -40,3 +42,5 @@ public static WebApplication MapEndpointsFromTestAssembly(this WebApplication ap
4042
return app;
4143
}
4244
}
45+
46+
#pragma warning restore ASP0018

tests/IeuanWalker.MinimalApi.Endpoints.Generator.Tests/Snapshots/DiagnosticSnapshotTests.DiagnosticMINAPI005_MultipleGroupCallsInConfigure_ShouldError#EndpointExtensions.g.verified.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace TestAssembly;
1515

16+
#pragma warning disable ASP0018 // Disable specific ASP.NET analyzer that warns about unused route parameters in generated handlers
17+
1618
public static class EndpointExtensions
1719
{
1820
public static IHostApplicationBuilder AddEndpoints(this IHostApplicationBuilder builder) => builder.AddEndpointsFromTestAssembly();
@@ -40,3 +42,5 @@ public static WebApplication MapEndpointsFromTestAssembly(this WebApplication ap
4042
return app;
4143
}
4244
}
45+
46+
#pragma warning restore ASP0018

tests/IeuanWalker.MinimalApi.Endpoints.Generator.Tests/Snapshots/DiagnosticSnapshotTests.DiagnosticMINAPI006_UnusedEndpointGroup_ShouldWarn#EndpointExtensions.g.verified.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace TestAssembly;
1515

16+
#pragma warning disable ASP0018 // Disable specific ASP.NET analyzer that warns about unused route parameters in generated handlers
17+
1618
public static class EndpointExtensions
1719
{
1820
public static IHostApplicationBuilder AddEndpoints(this IHostApplicationBuilder builder) => builder.AddEndpointsFromTestAssembly();
@@ -40,3 +42,5 @@ public static WebApplication MapEndpointsFromTestAssembly(this WebApplication ap
4042
return app;
4143
}
4244
}
45+
46+
#pragma warning restore ASP0018

tests/IeuanWalker.MinimalApi.Endpoints.Generator.Tests/Snapshots/DiagnosticSnapshotTests.DiagnosticMINAPI007_MultipleValidatorsForSameType_ShouldError#EndpointExtensions.g.verified.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
namespace TestAssembly;
1717

18+
#pragma warning disable ASP0018 // Disable specific ASP.NET analyzer that warns about unused route parameters in generated handlers
19+
1820
public static class EndpointExtensions
1921
{
2022
public static IHostApplicationBuilder AddEndpoints(this IHostApplicationBuilder builder) => builder.AddEndpointsFromTestAssembly();
@@ -49,3 +51,5 @@ public static WebApplication MapEndpointsFromTestAssembly(this WebApplication ap
4951
return app;
5052
}
5153
}
54+
55+
#pragma warning restore ASP0018

tests/IeuanWalker.MinimalApi.Endpoints.Generator.Tests/Snapshots/DiagnosticSnapshotTests.DiagnosticMINAPI008_ValidatorButValidationDisabled_ShouldWarn#EndpointExtensions.g.verified.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
namespace TestAssembly;
1717

18+
#pragma warning disable ASP0018 // Disable specific ASP.NET analyzer that warns about unused route parameters in generated handlers
19+
1820
public static class EndpointExtensions
1921
{
2022
public static IHostApplicationBuilder AddEndpoints(this IHostApplicationBuilder builder) => builder.AddEndpointsFromTestAssembly();
@@ -45,3 +47,5 @@ public static WebApplication MapEndpointsFromTestAssembly(this WebApplication ap
4547
return app;
4648
}
4749
}
50+
51+
#pragma warning restore ASP0018

tests/IeuanWalker.MinimalApi.Endpoints.Generator.Tests/Snapshots/DiagnosticSnapshotTests.DiagnosticMINAPI009_AbstractValidatorInheritanceChain_ShouldWarn#EndpointExtensions.g.verified.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace TestAssembly;
1515

16+
#pragma warning disable ASP0018 // Disable specific ASP.NET analyzer that warns about unused route parameters in generated handlers
17+
1618
public static class EndpointExtensions
1719
{
1820
public static IHostApplicationBuilder AddEndpoints(this IHostApplicationBuilder builder) => builder.AddEndpointsFromTestAssembly();
@@ -40,3 +42,5 @@ public static WebApplication MapEndpointsFromTestAssembly(this WebApplication ap
4042
return app;
4143
}
4244
}
45+
46+
#pragma warning restore ASP0018

tests/IeuanWalker.MinimalApi.Endpoints.Generator.Tests/Snapshots/DiagnosticSnapshotTests.DiagnosticMINAPI009_AbstractValidatorNotMatchingRequestType_ShouldNotWarn#EndpointExtensions.g.verified.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace TestAssembly;
1515

16+
#pragma warning disable ASP0018 // Disable specific ASP.NET analyzer that warns about unused route parameters in generated handlers
17+
1618
public static class EndpointExtensions
1719
{
1820
public static IHostApplicationBuilder AddEndpoints(this IHostApplicationBuilder builder) => builder.AddEndpointsFromTestAssembly();
@@ -40,3 +42,5 @@ public static WebApplication MapEndpointsFromTestAssembly(this WebApplication ap
4042
return app;
4143
}
4244
}
45+
46+
#pragma warning restore ASP0018

tests/IeuanWalker.MinimalApi.Endpoints.Generator.Tests/Snapshots/DiagnosticSnapshotTests.DiagnosticMINAPI009_AbstractValidatorOnRequest_ShouldWarn#EndpointExtensions.g.verified.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace TestAssembly;
1515

16+
#pragma warning disable ASP0018 // Disable specific ASP.NET analyzer that warns about unused route parameters in generated handlers
17+
1618
public static class EndpointExtensions
1719
{
1820
public static IHostApplicationBuilder AddEndpoints(this IHostApplicationBuilder builder) => builder.AddEndpointsFromTestAssembly();
@@ -40,3 +42,5 @@ public static WebApplication MapEndpointsFromTestAssembly(this WebApplication ap
4042
return app;
4143
}
4244
}
45+
46+
#pragma warning restore ASP0018

0 commit comments

Comments
 (0)