Skip to content

Commit

Permalink
Improve message for MA0115
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou committed Jun 15, 2024
1 parent 053e1e4 commit f9f92c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
Expand All @@ -15,7 +16,7 @@ public sealed class DoNotUseUnknownParameterForRazorComponentAnalyzer : Diagnost
private static readonly DiagnosticDescriptor Rule = new(
RuleIdentifiers.DoNotUseUnknownParameterForRazorComponent,
title: "Unknown component parameter",
messageFormat: "The parameter '{0}' does not exist on component '{1}'",
messageFormat: "The parameter '{0}' does not exist on component '{1}'. Available parameters: {2}.",
RuleCategories.Usage,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
Expand Down Expand Up @@ -85,7 +86,8 @@ public void AnalyzeBlockOptions(OperationAnalysisContext context)
var reportPascalCaseUnmatchedParameter = context.Options.GetConfigurationValue(operation, "MA0115.ReportPascalCaseUnmatchedParameter", defaultValue: true);
if (!IsValidAttribute(currentComponent, parameterName, reportPascalCaseUnmatchedParameter))
{
context.ReportDiagnostic(Rule, invocation.Syntax, parameterName, currentComponent.ToDisplayString(NullableFlowState.None));
var availableParameters = string.Join(", ", GetComponentDescriptor(currentComponent).Parameters.Order(StringComparer.Ordinal));
context.ReportDiagnostic(Rule, invocation.Syntax, parameterName, currentComponent.ToDisplayString(NullableFlowState.None), availableParameters);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Renderin
""";
await CreateProjectBuilder()
.WithSourceCode(Usings + sourceCode + ComponentWithCaptureUnmatchedValues)
.ShouldReportDiagnosticWithMessage("The parameter 'UnknownParams' does not exist on component 'SampleComponent'. Available parameters: Param1, Param2.")
.AddAnalyzerConfiguration("MA0115.ReportPascalCaseUnmatchedParameter", "true")
.ValidateAsync();
}
Expand Down

0 comments on commit f9f92c6

Please sign in to comment.