Skip to content

Commit f2a1401

Browse files
committed
Fixup
1 parent 4a4bfcf commit f2a1401

15 files changed

+30
-354
lines changed

AspNetCore.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,11 +1642,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "testassets", "testassets",
16421642
EndProject
16431643
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Identity.DefaultUI.WebSite", "src\Identity\testassets\Identity.DefaultUI.WebSite\Identity.DefaultUI.WebSite.csproj", "{835A4E0F-A697-4B69-9736-3E99D163C4B9}"
16441644
EndProject
1645-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.App.Analyzer", "src\Framework\Analyzer\src\Microsoft.AspNetCore.App.Analyzer.csproj", "{564CABB8-1B3F-4D9E-909D-260EF2B8614A}"
1645+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.App.Analyzer", "src\Framework\Analyzer\src\Microsoft.AspNetCore.App.Analyzers.csproj", "{564CABB8-1B3F-4D9E-909D-260EF2B8614A}"
16461646
EndProject
16471647
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Analyzer", "Analyzer", "{EE39397E-E4AF-4D3F-9B9C-D637F9222CDD}"
16481648
EndProject
1649-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.App.Analyzer.Test", "src\Framework\Analyzer\test\Microsoft.AspNetCore.App.Analyzer.Test.csproj", "{CF4CEC18-798D-46EC-B0A0-98D97496590F}"
1649+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.App.Analyzer.Test", "src\Framework\Analyzer\test\Microsoft.AspNetCore.App.Analyzers.Test.csproj", "{CF4CEC18-798D-46EC-B0A0-98D97496590F}"
16501650
EndProject
16511651
Global
16521652
GlobalSection(SolutionConfigurationPlatforms) = preSolution

src/Analyzers/Analyzers/src/StartupAnalysisBuilder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections.Generic;
@@ -18,7 +18,9 @@ public StartupAnalysisBuilder(StartupAnalyzer analyzer, StartupSymbols startupSy
1818
_analyzer = analyzer;
1919
StartupSymbols = startupSymbols;
2020

21-
_analysesByType = new Dictionary<INamedTypeSymbol, List<object>>();
21+
#pragma warning disable RS1024 // Compare symbols correctly
22+
_analysesByType = new Dictionary<INamedTypeSymbol, List<object>>(SymbolEqualityComparer.Default);
23+
#pragma warning restore RS1024 // Compare symbols correctly
2224
_lock = new object();
2325
}
2426

src/Analyzers/Analyzers/src/StartupAnalyzer.Diagnostics.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static Diagnostics()
3838

3939
internal static readonly DiagnosticDescriptor UnsupportedUseMvcWithEndpointRouting = new DiagnosticDescriptor(
4040
"MVC1005",
41-
"Cannot use UseMvc with Endpoint Routing.",
41+
"Cannot use UseMvc with Endpoint Routing",
4242
"Using '{0}' to configure MVC is not supported while using Endpoint Routing. To continue using '{0}', please set 'MvcOptions.EnableEndpointRouting = false' inside '{1}'.",
4343
"Usage",
4444
DiagnosticSeverity.Warning,
@@ -47,8 +47,8 @@ static Diagnostics()
4747

4848
internal static readonly DiagnosticDescriptor IncorrectlyConfiguredAuthorizationMiddleware = new DiagnosticDescriptor(
4949
"ASP0001",
50-
"Authorization middleware is incorrectly configured.",
51-
"The call to UseAuthorization should appear between app.UseRouting() and app.UseEndpoints(..) for authorization to be correctly evaluated.",
50+
"Authorization middleware is incorrectly configured",
51+
"The call to UseAuthorization should appear between app.UseRouting() and app.UseEndpoints(..) for authorization to be correctly evaluated",
5252
"Usage",
5353
DiagnosticSeverity.Warning,
5454
isEnabledByDefault: true,

src/Components/Web.JS/dist/Release/blazor.server.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Framework/Analyzer/src/Microsoft.AspNetCore.App.Analyzer.csproj renamed to src/Framework/Analyzer/src/Microsoft.AspNetCore.App.Analyzers.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<Reference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="All" />
1414
<Reference Include="System.Memory" />
1515

16-
<InternalsVisibleTo Include="Microsoft.AspNetCore.App.Analyzer.Test" />
16+
<InternalsVisibleTo Include="Microsoft.AspNetCore.App.Analyzers.Test" />
1717
</ItemGroup>
1818

1919
<ItemGroup>
Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Collections.Immutable;
54
using Microsoft.CodeAnalysis;
65

76
namespace Microsoft.AspNetCore.Analyzers.MinimalActions
@@ -11,31 +10,11 @@ internal static class DiagnosticDescriptors
1110
{
1211
internal static readonly DiagnosticDescriptor DoNotUseModelBindingAttributesOnMinimalActionParameters = new(
1312
"ASP0003",
14-
"Do not use model binding attributes with minimal actions",
15-
"Attribute '{0}' should not be specified for a minimal action parameter",
13+
"Do not use model binding attributes with Map actions",
14+
"{0} should not be specified for a {1} delegate parameter",
1615
"Usage",
1716
DiagnosticSeverity.Warning,
1817
isEnabledByDefault: true,
1918
helpLinkUri: "https://aka.ms/minimal-action/analyzer");
20-
21-
internal static readonly DiagnosticDescriptor RouteValueIsUnused = new(
22-
"ASP0004",
23-
"Route value is unused",
24-
"The route value '{0}' does not get bound and can be removed",
25-
"Usage",
26-
DiagnosticSeverity.Warning,
27-
isEnabledByDefault: true,
28-
helpLinkUri: "https://aka.ms/minimal-action/analyzer");
29-
30-
internal static readonly DiagnosticDescriptor RouteParameterCannotBeBound = new(
31-
"ASP0005",
32-
"Route parameter is not bound",
33-
"Route parameter does not have a corresponding route token and cannot be bound",
34-
"Usage",
35-
DiagnosticSeverity.Warning,
36-
isEnabledByDefault: true,
37-
helpLinkUri: "https://aka.ms/minimal-action/analyzer");
38-
39-
4019
}
4120
}

src/Framework/Analyzer/src/MinimalActions/DisallowMvcBindArgumentsOnParameters.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using Microsoft.CodeAnalysis;
66
using Microsoft.CodeAnalysis.Diagnostics;
7+
using Microsoft.CodeAnalysis.Operations;
78

89
namespace Microsoft.AspNetCore.Analyzers.MinimalActions;
910

@@ -12,6 +13,7 @@ public partial class MinimalActionAnalyzer : DiagnosticAnalyzer
1213
private static void DisallowMvcBindArgumentsOnParameters(
1314
in OperationAnalysisContext context,
1415
WellKnownTypes wellKnownTypes,
16+
IInvocationOperation invocation,
1517
IMethodSymbol methodSymbol)
1618
{
1719
foreach (var parameter in methodSymbol.Parameters)
@@ -28,10 +30,13 @@ private static void DisallowMvcBindArgumentsOnParameters(
2830
location = syntax.GetLocation();
2931
}
3032

33+
var methodName = invocation.TargetMethod.Name;
34+
3135
context.ReportDiagnostic(Diagnostic.Create(
3236
DiagnosticDescriptors.DoNotUseModelBindingAttributesOnMinimalActionParameters,
3337
location,
34-
modelBindingAttribute.AttributeClass.Name));
38+
modelBindingAttribute.AttributeClass.Name,
39+
methodName));
3540
}
3641
}
3742
}

src/Framework/Analyzer/src/MinimalActions/MinimalActionAnalyzer.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ public partial class MinimalActionAnalyzer : DiagnosticAnalyzer
1616
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(new[]
1717
{
1818
DiagnosticDescriptors.DoNotUseModelBindingAttributesOnMinimalActionParameters,
19-
DiagnosticDescriptors.RouteValueIsUnused,
20-
DiagnosticDescriptors.RouteParameterCannotBeBound,
2119
});
2220

2321
public override void Initialize(AnalysisContext context)
@@ -51,13 +49,12 @@ public override void Initialize(AnalysisContext context)
5149
if (delegateCreation.Target.Kind == OperationKind.AnonymousFunction)
5250
{
5351
var lambda = ((IAnonymousFunctionOperation)delegateCreation.Target);
54-
DisallowMvcBindArgumentsOnParameters(in operationAnalysisContext, wellKnownTypes, lambda.Symbol);
55-
RouteAttributeMismatch(in operationAnalysisContext, wellKnownTypes, invocation, lambda.Symbol);
52+
DisallowMvcBindArgumentsOnParameters(in operationAnalysisContext, wellKnownTypes, invocation, lambda.Symbol);
5653
}
5754
else if (delegateCreation.Target.Kind == OperationKind.MethodReference)
5855
{
5956
var methodReference = (IMethodReferenceOperation)delegateCreation.Target;
60-
DisallowMvcBindArgumentsOnParameters(in operationAnalysisContext, wellKnownTypes, methodReference.Method);
57+
DisallowMvcBindArgumentsOnParameters(in operationAnalysisContext, wellKnownTypes, invocation, methodReference.Method);
6158
}
6259
}, OperationKind.Invocation);
6360
});

src/Framework/Analyzer/src/MinimalActions/RouteAttributeMismatch.cs

Lines changed: 0 additions & 167 deletions
This file was deleted.

src/Framework/Analyzer/src/MinimalActions/WellKnownTypes.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,11 @@ public static bool TryCreate(Compilation compilation, [NotNullWhen(true)] out We
3131
return false;
3232
}
3333

34-
const string IFromRouteMetadata = "Microsoft.AspNetCore.Http.Metadata.IFromRouteMetadata";
35-
if (compilation.GetTypeByMetadataName(IFromRouteMetadata) is not { } iFromRouteMetadata)
36-
{
37-
return false;
38-
}
39-
4034
wellKnownTypes = new WellKnownTypes
4135
{
4236
MinimalActionEndpointRouteBuilderExtensions = minimalActionEndpointRouteBuilderExtensions,
4337
IBinderTypeProviderMetadata = ibinderTypeProviderMetadata,
4438
BindAttribute = bindAttribute,
45-
IFromRouteMetadata = iFromRouteMetadata,
4639
};
4740

4841
return true;
@@ -51,5 +44,4 @@ public static bool TryCreate(Compilation compilation, [NotNullWhen(true)] out We
5144
public ITypeSymbol MinimalActionEndpointRouteBuilderExtensions { get; private init; }
5245
public INamedTypeSymbol IBinderTypeProviderMetadata { get; private init; }
5346
public INamedTypeSymbol BindAttribute { get; private init; }
54-
public INamedTypeSymbol IFromRouteMetadata { get; private init; }
5547
}

src/Framework/Analyzer/test/Microsoft.AspNetCore.App.Analyzer.Test.csproj renamed to src/Framework/Analyzer/test/Microsoft.AspNetCore.App.Analyzers.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<ProjectReference Include="..\src\Microsoft.AspNetCore.App.Analyzer.csproj" />
14+
<ProjectReference Include="..\src\Microsoft.AspNetCore.App.Analyzers.csproj" />
1515
<ProjectReference Include="$(RepoRoot)src\Analyzers\Microsoft.AspNetCore.Analyzer.Testing\src\Microsoft.AspNetCore.Analyzer.Testing.csproj" />
1616
<Reference Include="Microsoft.AspNetCore" />
1717
<Reference Include="Microsoft.AspNetCore.Mvc" />

src/Framework/Analyzer/test/MinimalActions/DisallowMvcBindArgumentsOnParametersTest.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Globalization;
45
using Microsoft.AspNetCore.Analyzer.Testing;
56
using Xunit;
67

@@ -60,6 +61,7 @@ public async Task MinimalAction_Lambda_WithBindAttributes_ProducesDiagnostics()
6061
var diagnostic = Assert.Single(diagnostics);
6162
Assert.Same(DiagnosticDescriptors.DoNotUseModelBindingAttributesOnMinimalActionParameters, diagnostic.Descriptor);
6263
AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location);
64+
Assert.Equal("BindAttribute should not be specified for a MapGet delegate parameter", diagnostic.GetMessage(CultureInfo.InvariantCulture));
6365
}
6466

6567
[Fact]
@@ -72,7 +74,7 @@ public async Task MinimalAction_MethodReference_WithBindAttributes_ProducesDiagn
7274
var webApp = WebApplication.Create();
7375
webApp.MapPost(""/"", PostWithBind);
7476
75-
static void PostWithBind(/*MM*/[Bind] string name) {}
77+
static void PostWithBind(/*MM*/[ModelBinder] string name) {}
7678
");
7779
// Act
7880
var diagnostics = await Runner.GetDiagnosticsAsync(source.Source);
@@ -81,6 +83,7 @@ static void PostWithBind(/*MM*/[Bind] string name) {}
8183
var diagnostic = Assert.Single(diagnostics);
8284
Assert.Same(DiagnosticDescriptors.DoNotUseModelBindingAttributesOnMinimalActionParameters, diagnostic.Descriptor);
8385
AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location);
86+
Assert.Equal("ModelBinderAttribute should not be specified for a MapPost delegate parameter", diagnostic.GetMessage(CultureInfo.InvariantCulture));
8487
}
8588
}
8689

0 commit comments

Comments
 (0)