Skip to content

Commit 1c24d8d

Browse files
committed
Fix warnings.
1 parent 047852f commit 1c24d8d

6 files changed

Lines changed: 19 additions & 7 deletions

File tree

AspNetCoreAnalyzers/.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ dotnet_diagnostic.SA0001.severity = none
66
dotnet_diagnostic.SA1401.severity = none
77
# SA1633: The file header is missing or not located at the top of the file.
88
dotnet_diagnostic.SA1633.severity = none
9+
10+
# RS2008: Enable analyzer release tracking
11+
dotnet_diagnostic.RS2008.severity = none

AspNetCoreAnalyzers/Analyzers/AttributeAnalyzer.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ bool HasWrongType(IParameterSymbol parameterSymbol, out Replacement<TypeSyntax>
337337
{
338338
// https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-2.2#route-constraint-reference
339339
if (TryGetType(constraint.Span, out var type) &&
340-
parameterSymbol.TrySingleDeclaration(context.CancellationToken, out var parameter))
340+
parameterSymbol.TrySingleDeclaration(context.CancellationToken, out var parameter) &&
341+
parameter is { Type: { } })
341342
{
342343
newType = new Replacement<TypeSyntax>(
343344
parameter.Type,
@@ -351,7 +352,8 @@ bool HasWrongType(IParameterSymbol parameterSymbol, out Replacement<TypeSyntax>
351352
if (constraint.Span.Equals("?", StringComparison.Ordinal) &&
352353
parameterSymbol.Type.IsValueType &&
353354
parameterSymbol.Type.OriginalDefinition.SpecialType != SpecialType.System_Nullable_T &&
354-
parameterSymbol.TrySingleDeclaration(context.CancellationToken, out parameter))
355+
parameterSymbol.TrySingleDeclaration(context.CancellationToken, out parameter) &&
356+
parameter is { Type: { } })
355357
{
356358
newType = new Replacement<TypeSyntax>(
357359
parameter.Type,
@@ -368,7 +370,8 @@ bool HasWrongType(IParameterSymbol parameterSymbol, out Replacement<TypeSyntax>
368370
parameterSymbol.Type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T &&
369371
parameterSymbol.Type is INamedTypeSymbol namedType &&
370372
namedType.TypeArguments.TrySingle(out var typeArg) &&
371-
parameterSymbol.TrySingleDeclaration(context.CancellationToken, out var parameter))
373+
parameterSymbol.TrySingleDeclaration(context.CancellationToken, out var parameter) &&
374+
parameter is { Type: { } })
372375
{
373376
newType = new Replacement<TypeSyntax>(
374377
parameter.Type,

AspNetCoreAnalyzers/CodeFixes/ParameterTypeFix.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ protected override async Task RegisterCodeFixesAsync(DocumentEditorCodeFixContex
2323

2424
foreach (var diagnostic in context.Diagnostics)
2525
{
26-
if (syntaxRoot.TryFindNodeOrAncestor(diagnostic, out TypeSyntax? typeSyntax) &&
26+
if (syntaxRoot is { } &&
27+
syntaxRoot.TryFindNodeOrAncestor(diagnostic, out TypeSyntax? typeSyntax) &&
2728
diagnostic.Properties.TryGetValue(nameof(TypeSyntax), out var typeName))
2829
{
2930
context.RegisterCodeFix(

AspNetCoreAnalyzers/CodeFixes/RenameParameterFix.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
2828
.ConfigureAwait(false);
2929
foreach (var diagnostic in context.Diagnostics)
3030
{
31-
if (syntaxRoot.TryFindNodeOrAncestor(diagnostic, out ParameterSyntax? parameterSyntax) &&
31+
if (syntaxRoot is { } &&
32+
syntaxRoot.TryFindNodeOrAncestor(diagnostic, out ParameterSyntax? parameterSyntax) &&
33+
semanticModel is { } &&
3234
semanticModel.TryGetSymbol(parameterSyntax, context.CancellationToken, out var parameter) &&
3335
diagnostic.Properties.TryGetValue(nameof(NameSyntax), out var name))
3436
{

AspNetCoreAnalyzers/CodeFixes/RenameTypeFix.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
2828
.ConfigureAwait(false);
2929
foreach (var diagnostic in context.Diagnostics)
3030
{
31-
if (syntaxRoot.TryFindNodeOrAncestor(diagnostic, out ClassDeclarationSyntax? classDeclarationSyntax) &&
31+
if (syntaxRoot is { } &&
32+
syntaxRoot.TryFindNodeOrAncestor(diagnostic, out ClassDeclarationSyntax? classDeclarationSyntax) &&
33+
semanticModel is { } &&
3234
semanticModel.TryGetSymbol(classDeclarationSyntax, context.CancellationToken, out var parameter) &&
3335
diagnostic.Properties.TryGetValue(nameof(NameSyntax), out var name))
3436
{

AspNetCoreAnalyzers/CodeFixes/TemplateTextFix.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ protected override async Task RegisterCodeFixesAsync(DocumentEditorCodeFixContex
3131

3232
foreach (var diagnostic in context.Diagnostics)
3333
{
34-
if (syntaxRoot.TryFindNodeOrAncestor<LiteralExpressionSyntax>(diagnostic, out var literal) &&
34+
if (syntaxRoot is { } &&
35+
syntaxRoot.TryFindNodeOrAncestor<LiteralExpressionSyntax>(diagnostic, out var literal) &&
3536
diagnostic.Properties.TryGetValue(nameof(UrlTemplate), out var text))
3637
{
3738
context.RegisterCodeFix(

0 commit comments

Comments
 (0)