Repository navigation
Add warning and code fix suggestion for non-public [JSInvokable] methods - #67137
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds analyzer/code-fix support for [JSInvokable] methods needing to be public static, and improves the existing component-parameter code fix to correctly handle properties with multiple accessibility modifiers.
Changes:
- Added
JSInvokableAnalyzerdiagnostics (BL0012,BL0013) plus a code fix that makes methodspublic static. - Added analyzer/code-fix tests and shared test declarations for
JSInvokableAttribute. - Updated
ComponentParametersShouldBePublicCodeFixProviderto rewrite modifier lists more robustly, plus new tests for multi-modifier properties.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Tools/SDK-Analyzers/Components/test/ComponentParametersShouldBePublicCodeFixProviderTest.cs | Adds coverage for multi-modifier parameter properties. |
| src/Tools/SDK-Analyzers/Components/src/ComponentParametersShouldBePublicCodeFixProvider.cs | Updates modifier rewrite logic to handle multi-modifier cases. |
| src/Components/Analyzers/test/JSInvokableCodeFixProviderTest.cs | Adds code-fix tests for making [JSInvokable] methods public static. |
| src/Components/Analyzers/test/JSInvokableAnalyzerTest.cs | Adds diagnostic tests for [JSInvokable] method requirements. |
| src/Components/Analyzers/test/ComponentsTestDeclarations.cs | Adds SourceWithJSInvokable test declaration for the attribute. |
| src/Components/Analyzers/test/ComponentParametersShouldBePublicCodeFixProviderTest.cs | Mirrors multi-modifier parameter-property coverage for this analyzer suite. |
| src/Components/Analyzers/src/Resources.resx | Adds resource strings for the new JSInvokable diagnostics and fix title. |
| src/Components/Analyzers/src/JSInvokableCodeFixProvider.cs | Introduces the code fix to rewrite method modifiers to public static. |
| src/Components/Analyzers/src/JSInvokableAnalyzer.cs | Introduces the analyzer that reports non-public / non-static [JSInvokable] methods. |
| src/Components/Analyzers/src/DiagnosticDescriptors.cs | Adds BL0012 / BL0013 diagnostic descriptors. |
| src/Components/Analyzers/src/ComponentParametersShouldBePublicCodeFixProvider.cs | Updates modifier rewrite logic to handle multi-modifier cases. |
d3370b8 to
d3d7360
Compare
d3d7360 to
985fe24
Compare
|
@dotnet-policy-service agree company="Infragistics, Inc" |
dariatiurina
left a comment
There was a problem hiding this comment.
Thank you for your work!
I am not sure about static part of the analyzers based on docs.
Also, can you please file new issue for the bug with existing analyzer and then fix it with new PR
[JSInvokable] methods[JSInvokable] methods
…Invokable methods
021ed3d to
5509c09
Compare
|
Went with normalizing line endings on source and result in the CodeFixVerifier, as the Helix tests apparently build on Windows (baking in CLRF in tests) and send jobs to Unix systems and there's already similar handling in: and of course some tests ignore those completely in the Assert: |
dariatiurina
left a comment
There was a problem hiding this comment.
Great work! Other than one test question I have no remarks.
Add Blazor Analyzer diagnostic warning and Code fix provider when a
[JSInvokable]method is not publicAdded new analyzer and code fix provider to convert
[JSInvokable]topublicDescription
Added diagnostic warning for


[JSInvokable]not beingpublic:And code fix to make public (should also handle multiple modifiers, related to #67365):
Closes #65235