Skip to content
Merged
Changes from all commits
Commits
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
14 changes: 12 additions & 2 deletions crates/oxc_linter/src/rules/oxc/no_async_endpoint_handlers.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::ops::Deref;

use oxc_allocator::{Address, GetAddress};
use oxc_ast::{
AstKind,
ast::{Argument, ArrowFunctionExpression, Expression, Function},
};
use oxc_diagnostics::{LabeledSpan, OxcDiagnostic};
use oxc_macros::declare_oxc_lint;
use oxc_span::{CompactStr, Span};
use rustc_hash::FxHashSet;
use serde_json::Value;

use crate::{AstNode, context::LintContext, rule::Rule, utils};
Expand Down Expand Up @@ -199,7 +201,8 @@ impl Rule for NoAsyncEndpointHandlers {

impl NoAsyncEndpointHandlers {
fn check_endpoint_arg<'a>(&self, ctx: &LintContext<'a>, arg: &Expression<'a>) {
self.check_endpoint_expr(ctx, None, None, arg);
let mut visited = FxHashSet::default();
self.check_endpoint_expr(ctx, None, None, arg, &mut visited);
}

fn check_endpoint_expr<'a>(
Expand All @@ -208,7 +211,13 @@ impl NoAsyncEndpointHandlers {
id_name: Option<&str>,
registered_at: Option<Span>,
arg: &Expression<'a>,
visited: &mut FxHashSet<Address>,
) {
let expr_ptr = arg.address();
if !visited.insert(expr_ptr) {
return;
}

match arg {
Expression::Identifier(handler) => {
// Unresolved reference? Nothing we can do.
Expand Down Expand Up @@ -240,7 +249,7 @@ impl NoAsyncEndpointHandlers {
return;
}
}
self.check_endpoint_expr(ctx, id_name, registered_at, init);
self.check_endpoint_expr(ctx, id_name, registered_at, init, visited);
}
}
_ => {}
Expand Down Expand Up @@ -351,6 +360,7 @@ fn test() {
",
None,
),
("{const{r}=r;e.delete(r)}", None),
];

let fail = vec![
Expand Down
Loading