Skip to content

Commit 6115c18

Browse files
author
Ryan Nowak
committed
Pranavs cool feedback
1 parent ace1eb6 commit 6115c18

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

src/Components/Analyzers/src/ComponentParameterAnalyzer.cs

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,56 +52,58 @@ public override void Initialize(AnalysisContext context)
5252
}
5353
}
5454

55-
if (properties.Count > 0)
55+
if (properties.Count == 0)
5656
{
57-
context.RegisterSymbolEndAction(context =>
58-
{
59-
var captureUnmatchedValuesParameters = new List<IPropertySymbol>();
57+
return;
58+
}
59+
60+
context.RegisterSymbolEndAction(context =>
61+
{
62+
var captureUnmatchedValuesParameters = new List<IPropertySymbol>();
6063

6164
// Per-property validations
6265
foreach (var property in properties)
66+
{
67+
if (property.SetMethod?.DeclaredAccessibility == Accessibility.Public)
6368
{
64-
if (property.SetMethod?.DeclaredAccessibility == Accessibility.Public)
65-
{
66-
context.ReportDiagnostic(Diagnostic.Create(
67-
DiagnosticDescriptors.ComponentParametersShouldNotBePublic,
68-
property.Locations[0],
69-
property.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat)));
70-
}
69+
context.ReportDiagnostic(Diagnostic.Create(
70+
DiagnosticDescriptors.ComponentParametersShouldNotBePublic,
71+
property.Locations[0],
72+
property.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat)));
73+
}
7174

72-
if (ComponentFacts.IsParameterWithCaptureUnmatchedValues(symbols, property))
73-
{
74-
captureUnmatchedValuesParameters.Add(property);
75+
if (ComponentFacts.IsParameterWithCaptureUnmatchedValues(symbols, property))
76+
{
77+
captureUnmatchedValuesParameters.Add(property);
7578

7679
// Check the type, we need to be able to assign a Dictionary<string, object>
7780
var conversion = context.Compilation.ClassifyConversion(symbols.ParameterCaptureUnmatchedValuesRuntimeType, property.Type);
78-
if (!conversion.Exists || conversion.IsExplicit)
79-
{
80-
context.ReportDiagnostic(Diagnostic.Create(
81-
DiagnosticDescriptors.ComponentParameterCaptureUnmatchedValuesHasWrongType,
82-
property.Locations[0],
83-
property.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat),
84-
property.Type.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat),
85-
symbols.ParameterCaptureUnmatchedValuesRuntimeType.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat)));
86-
}
81+
if (!conversion.Exists || conversion.IsExplicit)
82+
{
83+
context.ReportDiagnostic(Diagnostic.Create(
84+
DiagnosticDescriptors.ComponentParameterCaptureUnmatchedValuesHasWrongType,
85+
property.Locations[0],
86+
property.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat),
87+
property.Type.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat),
88+
symbols.ParameterCaptureUnmatchedValuesRuntimeType.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat)));
8789
}
8890
}
91+
}
8992

9093
// Check if the type defines multiple CaptureUnmatchedValues parameters. Doing this outside the loop means we place the
9194
// errors on the type.
9295
if (captureUnmatchedValuesParameters.Count > 1)
93-
{
94-
context.ReportDiagnostic(Diagnostic.Create(
95-
DiagnosticDescriptors.ComponentParameterCaptureUnmatchedValuesMustBeUnique,
96-
context.Symbol.Locations[0],
97-
type.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat),
96+
{
97+
context.ReportDiagnostic(Diagnostic.Create(
98+
DiagnosticDescriptors.ComponentParameterCaptureUnmatchedValuesMustBeUnique,
99+
context.Symbol.Locations[0],
100+
type.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat),
101+
Environment.NewLine,
102+
string.Join(
98103
Environment.NewLine,
99-
string.Join(
100-
Environment.NewLine,
101-
captureUnmatchedValuesParameters.Select(p => p.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat)).OrderBy(n => n))));
102-
}
103-
});
104-
}
104+
captureUnmatchedValuesParameters.Select(p => p.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat)).OrderBy(n => n))));
105+
}
106+
});
105107
}, SymbolKind.NamedType);
106108
});
107109
}

src/Components/Analyzers/src/ComponentSymbols.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Collections.Generic;
56
using Microsoft.CodeAnalysis;
67

78
namespace Microsoft.AspNetCore.Components.Analyzers
@@ -29,7 +30,7 @@ public static bool TryCreate(Compilation compilation, out ComponentSymbols symbo
2930
return false;
3031
}
3132

32-
var dictionary = compilation.GetTypeByMetadataName(ComponentsApi.SystemCollectionsGenericDictionary);
33+
var dictionary = compilation.GetTypeByMetadataName(typeof(Dictionary<,>).FullName);
3334
var @string = compilation.GetSpecialType(SpecialType.System_String);
3435
var @object = compilation.GetSpecialType(SpecialType.System_Object);
3536
if (dictionary == null || @string == null || @object == null)

src/Components/Analyzers/src/ComponentsApi.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ namespace Microsoft.AspNetCore.Components.Analyzers
77
// Keep these in sync with the actual definitions
88
internal static class ComponentsApi
99
{
10-
public static readonly string SystemCollectionsGenericDictionary = "System.Collections.Generic.Dictionary`2";
11-
1210
public static readonly string AssemblyName = "Microsoft.AspNetCore.Components";
1311

1412
public static class ParameterAttribute

0 commit comments

Comments
 (0)