Add analyzer for RazorComponentResult parameter validation#67617
Open
dkamburov wants to merge 8 commits into
Open
Add analyzer for RazorComponentResult parameter validation#67617dkamburov wants to merge 8 commits into
dkamburov wants to merge 8 commits into
Conversation
Contributor
|
Thanks for your PR, @dkamburov. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Author
|
@dotnet-policy-service agree company="Infragistics, Inc" |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new Components Roslyn analyzer (BL0015) to validate anonymous-object parameter names passed to RazorComponentResult<TComponent> at compile time, aiming to catch misspelled/invalid component parameter names before they produce runtime InvalidOperationExceptions.
Changes:
- Added
RazorComponentResultParameterAnalyzer(BL0015) to validate anonymous-object member names against component parameters. - Registered the diagnostic descriptor and added localized resource strings for title/description/message format.
- Added unit tests covering common scenarios (unknown names, inherited parameters, CaptureUnmatchedValues, dictionary overload, unrelated types).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Components/Analyzers/src/RazorComponentResultParameterAnalyzer.cs | Implements the BL0015 analyzer for RazorComponentResult<TComponent>(object parameters) anonymous-object validation. |
| src/Components/Analyzers/src/DiagnosticDescriptors.cs | Registers BL0015 descriptor metadata. |
| src/Components/Analyzers/src/ComponentsApi.cs | Adds RazorComponentResult<TComponent> metadata name constant for symbol lookup. |
| src/Components/Analyzers/src/Resources.resx | Adds BL0015 resource strings (title/description/format). |
| src/Components/Analyzers/test/RazorComponentResultParameterAnalyzerTest.cs | Adds unit tests for the analyzer behavior across key scenarios. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add analyzer for RazorComponentResult parameter validation
Adds a new Roslyn analyzer (BL0015) — RazorComponentResultParameterAnalyzer — that validates parameter names passed via anonymous objects to RazorComponentResult at compile time.
Description
Introduced RazorComponentResultParameterAnalyzer to warn (BL0015) when anonymous object parameters do not match component [Parameter] or [CascadingParameter] properties, unless unmatched values are captured. Registered the diagnostic, updated ComponentsApi, and added thorough unit tests covering various scenarios. Resource strings for the diagnostic were also added.
Fixes #51923