Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
830dc01
Add JSInterop analyzer ensuring 'IsInteractive' is checked before usi…
skrustev Jul 23, 2026
3db9392
Fix return when checking IsInteractive being reversed.
skrustev Jul 23, 2026
8f36884
Review comments fixes and code style.
skrustev Jul 23, 2026
2351bc2
Update diagnostics range.
skrustev Jul 23, 2026
93d8e05
Add ComponentFacts common to ForLoop and JSInterop analyzers with sin…
skrustev Aug 19, 2026
1ca7038
Add suppress for Children property warning for now.
skrustev Aug 19, 2026
19f4c63
Check If conditions as well for JSInterop calls.
skrustev Aug 19, 2026
531b4fb
Add event handlers analyze and method reference traverse with max dep…
skrustev Aug 19, 2026
f2eff0b
Add ability to test multiple analyzers at the same time. Add integrat…
skrustev Aug 19, 2026
10d60fe
Rename JSInterop analyzer checking for RenderMode.
skrustev Aug 19, 2026
03d8090
Rename test files as well.
skrustev Aug 19, 2026
6faa45c
Reuse IsComponentBase common implementation.
skrustev Aug 19, 2026
6c04079
Resolve lint empty row.
skrustev Aug 19, 2026
42b0b52
Merge master into skrastev/jsinterop-interactive-analyzer
skrustev Sep 8, 2026
481c24c
Bump up diagnostic id and add missing in docs.
skrustev Sep 8, 2026
5a0e61b
Improve hanling of OnInteractive check returning to cover possible ca…
skrustev Sep 16, 2026
e1da6c1
Merge branch 'main' into skrastev/jsinterop-interactive-analyzer
skrustev Sep 16, 2026
ac44981
Throw exception if analyzer is not registered for multiple analyzer t…
skrustev Sep 29, 2026
780c429
Ensure argument scanning and call traversal are all checked despite o…
skrustev Sep 29, 2026
0ec944b
Ensure reassigned variable is removed if no longer checks IsInteractive.
skrustev Sep 29, 2026
c1cbd8e
Cover local function cases and ensure only called ones are checked.
skrustev Sep 29, 2026
86b610c
Ensure state is isolated for anonymous functions used in callbacks.
skrustev Sep 29, 2026
b1913e7
Merge branch 'main' into skrastev/jsinterop-interactive-analyzer
skrustev Oct 20, 2026
5f364d9
Merge branch 'main' into skrastev/jsinterop-interactive-analyzer
skrustev Oct 27, 2026
828687a
Do not warn for DOM events. Apply for child components as well.
skrustev Oct 27, 2026
3a063db
Add warning for when JS interop result is stored.
skrustev Oct 27, 2026
becba03
Warn when lambda or method is stored in a local variable as well and …
skrustev Oct 27, 2026
b9d0491
Add condition matching regardless of IsInteractive call position. Inc…
skrustev Oct 27, 2026
bee7ca6
Optimize GetSemanticModel calls.
skrustev Oct 27, 2026
3b46f1c
Fix unnecessary warnings after throw.
skrustev Nov 17, 2026
f5de5af
Analyze try with its own state. Analyze catch/finally as well separat…
skrustev Nov 17, 2026
e5237c7
List and manually check related JSInterop type names, to avoid false …
skrustev Nov 17, 2026
cfd74d8
Invalidate local assigned IsInteractive passed by ref or out.
skrustev Nov 17, 2026
2e58cd4
Traverse Direct JS invocations in BuildRenderTree and take into accou…
skrustev Nov 17, 2026
48d965e
Add tests that verify that the receiver/resolved method belongs to Re…
skrustev Nov 17, 2026
5d17227
Stored delegates can now be tracked in parameters as well as locals.
skrustev Nov 17, 2026
741304e
Ensure only method that we are sure invoke delegates immediately are …
skrustev Nov 19, 2026
d5c5e83
Declare the real ComponentBase and RenderTreeBuilder contracts in tes…
skrustev Nov 19, 2026
04b6e99
Add test snippets compilation check to ensure that they compile witho…
skrustev Nov 19, 2026
83337fa
Merge branch 'main' into skrastev/jsinterop-interactive-analyzer
skrustev Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
| __`MVC1005`__ | Cannot use UseMvc with Endpoint Routing |
| __`MVC1006`__ | Methods containing TagHelpers must be async and return Task |

### BL (`BL0001-BL0020`)
### BL (`BL0001-BL0021`)

| Diagnostic ID | Description |
| :---------------- | :---------- |
Expand All @@ -91,6 +91,7 @@
| __`BL0018`__ | Component declares `DisposeAsync()` but does not implement `IAsyncDisposable` |
| __`BL0019`__ | Virtualize uses an invalid spacer element |
| __`BL0020`__ | RazorComponentResult parameter does not match a component parameter |
| __`BL0021`__ | JS interop used without checking RendererInfo.IsInteractive |

### Request Delegate Generator (`RDG001-RDG014`)

Expand Down
18 changes: 16 additions & 2 deletions src/Components/Analyzers/src/ComponentFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ public static bool IsComponentBase(ComponentSymbols symbols, INamedTypeSymbol ty
throw new ArgumentNullException(nameof(type));
}

if (symbols.ComponentBaseType == null)
return IsComponentBase(type, symbols.ComponentBaseType);
}

public static bool IsComponentBase(INamedTypeSymbol type, INamedTypeSymbol componentBaseType)
{
if (componentBaseType is null)
{
return false;
}
Expand All @@ -148,7 +153,7 @@ public static bool IsComponentBase(ComponentSymbols symbols, INamedTypeSymbol ty
var current = type.BaseType;
while (current != null)
{
if (SymbolEqualityComparer.Default.Equals(current, symbols.ComponentBaseType))
if (SymbolEqualityComparer.Default.Equals(current, componentBaseType))
{
return true;
}
Expand Down Expand Up @@ -178,4 +183,13 @@ public static bool IsComponent(ComponentSymbols symbols, Compilation compilation

return true;
}

public static bool IsBuildRenderTree(IMethodSymbol methodSymbol, INamedTypeSymbol componentBaseTypedSymbol)
{
if (componentBaseTypedSymbol is null || methodSymbol.Name != "BuildRenderTree" || !methodSymbol.IsOverride)
{
return false;
}
return IsComponentBase(methodSymbol.ContainingType, componentBaseTypedSymbol);
}
}
43 changes: 43 additions & 0 deletions src/Components/Analyzers/src/ComponentsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,47 @@ public static class RazorComponentResultOfT
// The generic type is defined in Microsoft.AspNetCore.Components.Endpoints and has arity 1.
public const string MetadataName = "Microsoft.AspNetCore.Http.HttpResults.RazorComponentResult`1";
}

public static class Dispatcher
{
public const string FullTypeName = "Microsoft.AspNetCore.Components.Dispatcher";
public const string MetadataName = FullTypeName;
}

public static class RendererInfo
{
public const string FullTypeName = "Microsoft.AspNetCore.Components.RendererInfo";
public const string MetadataName = FullTypeName;
public const string IsInteractive = "IsInteractive";
}

public static class RenderModeAttribute
{
public const string FullTypeName = "Microsoft.AspNetCore.Components.RenderModeAttribute";
public const string MetadataName = FullTypeName;
}

public static class JSInteropRuntime
{
public const string FullTypeName = "Microsoft.JSInterop.IJSRuntime";
public const string MetadataName = FullTypeName;
}

public static class JSObjectReference
{
public const string FullTypeName = "Microsoft.JSInterop.IJSObjectReference";
public const string MetadataName = FullTypeName;
}

public static class WebAssembly
{
public const string FullTypeName = "Microsoft.AspNetCore.Components.WebAssembly";
public const string MetadataName = FullTypeName;
}

public static class WebAssemblyServer
{
public const string FullTypeName = "Microsoft.AspNetCore.Components.WebAssembly.Server";
public const string MetadataName = FullTypeName;
}
}
11 changes: 10 additions & 1 deletion src/Components/Analyzers/src/DiagnosticDescriptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ internal static class DiagnosticDescriptors
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: CreateLocalizableResourceString(nameof(Resources.ComponentHasDisposeAsyncWithoutIAsyncDisposable_Description)));

public static readonly DiagnosticDescriptor VirtualizeSpacerElementIsInvalid = new(
"BL0019",
CreateLocalizableResourceString(nameof(Resources.VirtualizeSpacerElementIsInvalid_Title)),
Expand All @@ -192,4 +192,13 @@ internal static class DiagnosticDescriptors
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: CreateLocalizableResourceString(nameof(Resources.RazorComponentResultParameterDoesNotExist_Description)));

public static readonly DiagnosticDescriptor JsInteropUsageWithoutIsInteractiveCheck = new(
"BL0021",
CreateLocalizableResourceString(nameof(Resources.JsInteropUsageWithoutIsInteractiveCheck_Title)),
CreateLocalizableResourceString(nameof(Resources.JsInteropUsageWithoutIsInteractiveCheck_Format)),
Usage,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: CreateLocalizableResourceString(nameof(Resources.JsInteropUsageWithoutIsInteractiveCheck_Description)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override void Initialize(AnalysisContext context)
{
var analyzerState = new ForLoopAnalyzerState();
if (blockContext.OwningSymbol is IMethodSymbol owningMethod
&& IsImplementationOfBuildRenderTree(owningMethod, availableTypes))
&& ComponentFacts.IsBuildRenderTree(owningMethod, availableTypes[ComponentsApi.ComponentBase.MetadataName]))
{
foreach (var childBlock in blockContext.OperationBlocks)
{
Expand All @@ -68,24 +68,6 @@ public override void Initialize(AnalysisContext context)
});
}

private static bool IsImplementationOfBuildRenderTree(IMethodSymbol methodSymbol, Dictionary<string, INamedTypeSymbol?> availableTypes)
{
if (methodSymbol.Name != "BuildRenderTree" || !methodSymbol.IsOverride)
{
return false;
}
var containingType = methodSymbol.ContainingType;
while (containingType is not null)
{
if (SymbolEqualityComparer.Default.Equals(containingType, availableTypes[ComponentsApi.ComponentBase.MetadataName]))
{
return true;
}
containingType = containingType.BaseType;
}
return false;
}

private static void AnalyzeOperationsTree(IOperation operation, Dictionary<string, INamedTypeSymbol?> availableTypes, ForLoopAnalyzerState analyzerState)
{
if (operation is IForLoopOperation forLoopOperation)
Expand Down
Loading
Loading