Skip to content

Add warning and code fix suggestion for non-public/static [JSInvokable] methods#67137

Draft
damyanpetev wants to merge 2 commits into
dotnet:mainfrom
damyanpetev:dpetev/jsinvokable-analyzer
Draft

Add warning and code fix suggestion for non-public/static [JSInvokable] methods#67137
damyanpetev wants to merge 2 commits into
dotnet:mainfrom
damyanpetev:dpetev/jsinvokable-analyzer

Conversation

@damyanpetev

Copy link
Copy Markdown

Add Blazor Analyzer diagnostic warning and Code fix provider when a [JSInvokable] method is not public and/or static

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Added new analyzer and code fix provider, plus a small fix for an old code fix provider with similar logic.

Description

Note: Includes a small fix (first commit) for an existing ComponentParametersShouldBePublicCodeFixProvider as it was modifying the SyntaxTokenList while iterating, causing attempts to remove beyond the first to fail, leaving resulting code in wrong state with likely compiler errors - usually CS0107.
Can move to a separate PR if that goes too out of scope for this one.

Added two diagnostic warnings - one for [JSInvokable] not being public and one for it not being static since I saw that was also not covered. Could merge into a single warning in case the two are too noisy.
image
The code fix handles both at the same time regardless.

Closes #65235

…fier handling

ComponentParametersShouldBePublicCodeFixProvider was modifying the SyntaxTokenList
while iterating, causing attempts to remove beyond the first to fail, leaving
resulting code in worng state with likely compiler errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Blazor] Warn + suggest code fix when a [JSInvokable] method is non-public.*

1 participant