Skip to content

Commit a532ebc

Browse files
committed
Refactor ASP003
1 parent 23a8fca commit a532ebc

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

AspNetCoreAnalyzers.Tests/ASP003ParameterTypeTests/CodeFix.cs renamed to AspNetCoreAnalyzers.Tests/ASP003ParameterSymbolTypeTests/CodeFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace AspNetCoreAnalyzers.Tests.ASP003ParameterTypeTests
88
public class CodeFix
99
{
1010
private static readonly DiagnosticAnalyzer Analyzer = new AttributeAnalyzer();
11-
private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(ASP003ParameterType.Descriptor);
11+
private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(ASP003ParameterSymbolType.Descriptor);
1212
private static readonly CodeFixProvider Fix = new ParameterTypeFix();
1313

1414
[TestCase("\"{id:int}\"", "int id")]

AspNetCoreAnalyzers.Tests/ASP003ParameterTypeTests/ValidCode.cs renamed to AspNetCoreAnalyzers.Tests/ASP003ParameterSymbolTypeTests/ValidCode.cs

File renamed without changes.

AspNetCoreAnalyzers/ASP003ParameterType.cs renamed to AspNetCoreAnalyzers/ASP003ParameterSymbolType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace AspNetCoreAnalyzers
22
{
33
using Microsoft.CodeAnalysis;
44

5-
internal static class ASP003ParameterType
5+
internal static class ASP003ParameterSymbolType
66
{
77
public const string DiagnosticId = "ASP003";
88

AspNetCoreAnalyzers/Analyzers/AttributeAnalyzer.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class AttributeAnalyzer : DiagnosticAnalyzer
1717
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(
1818
ASP001ParameterName.Descriptor,
1919
ASP002MissingParameter.Descriptor,
20-
ASP003ParameterType.Descriptor,
20+
ASP003ParameterSymbolType.Descriptor,
2121
ASP005ParameterSyntax.Descriptor,
2222
ASP006ParameterRegex.Descriptor);
2323

@@ -77,12 +77,12 @@ context.ContainingSymbol is IMethodSymbol method &&
7777

7878
foreach (var pair in pairs)
7979
{
80-
if (HasWrongType(pair, out var typeName) &&
80+
if (HasWrongType(pair, out var typeName, out _) &&
8181
methodDeclaration.TryFindParameter(pair.Symbol?.Name, out parameterSyntax))
8282
{
8383
context.ReportDiagnostic(
8484
Diagnostic.Create(
85-
ASP003ParameterType.Descriptor,
85+
ASP003ParameterSymbolType.Descriptor,
8686
parameterSyntax.Type.GetLocation(),
8787
ImmutableDictionary<string, string>.Empty.Add(
8888
nameof(TypeSyntax),
@@ -182,7 +182,7 @@ private static PooledList<ParameterPair> GetPairs(UrlTemplate template, IMethodS
182182
return list;
183183
}
184184

185-
private static bool HasWrongType(ParameterPair pair, out string correctType)
185+
private static bool HasWrongType(ParameterPair pair, out string correctType, out string correctConstraint)
186186
{
187187
if (pair.Route?.Constraints is ImmutableArray<RouteConstraint> constraints &&
188188
pair.Symbol is IParameterSymbol parameter)
@@ -193,6 +193,7 @@ private static bool HasWrongType(ParameterPair pair, out string correctType)
193193
if (TryGetType(constraint.Span, out var type))
194194
{
195195
correctType = parameter.Type == type ? null : type.Alias ?? type.FullName;
196+
correctConstraint = null;
196197
return correctType != null;
197198
}
198199
}
@@ -203,10 +204,12 @@ parameter.Type is INamedTypeSymbol namedType &&
203204
namedType.TypeArguments.TrySingle(out var typeArg))
204205
{
205206
correctType = typeArg.ToString();
207+
correctConstraint = null;
206208
return true;
207209
}
208210
}
209211

212+
correctConstraint = null;
210213
correctType = null;
211214
return false;
212215

AspNetCoreAnalyzers/CodeFixes/ParameterTypeFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace AspNetCoreAnalyzers
1414
public class ParameterTypeFix : DocumentEditorCodeFixProvider
1515
{
1616
public override ImmutableArray<string> FixableDiagnosticIds { get; } = ImmutableArray.Create(
17-
ASP003ParameterType.DiagnosticId);
17+
ASP003ParameterSymbolType.DiagnosticId);
1818

1919
protected override async Task RegisterCodeFixesAsync(DocumentEditorCodeFixContext context)
2020
{

0 commit comments

Comments
 (0)