diff --git a/crates/oxc_linter/src/rules/oxc/no_async_await.rs b/crates/oxc_linter/src/rules/oxc/no_async_await.rs index 7d975d066731a..3242144165095 100644 --- a/crates/oxc_linter/src/rules/oxc/no_async_await.rs +++ b/crates/oxc_linter/src/rules/oxc/no_async_await.rs @@ -89,13 +89,12 @@ impl Rule for NoAsyncAwait { /// "async".len() const ASYNC_LEN: u32 = 5; -#[expect(clippy::cast_possible_truncation)] fn report_on_async_span(async_span: Span, ctx: &LintContext<'_>) { // find the `async` keyword within the span and report on it - let Some(async_keyword_offset) = ctx.source_range(async_span).find("async") else { + let Some(async_keyword_offset) = ctx.find_next_token_from(async_span.start, "async") else { return; }; - let async_keyword_span = Span::sized(async_span.start + async_keyword_offset as u32, ASYNC_LEN); + let async_keyword_span = Span::sized(async_span.start + async_keyword_offset, ASYNC_LEN); ctx.diagnostic(no_async_diagnostic(async_keyword_span)); } @@ -156,6 +155,8 @@ fn test() { } } ", + "/* async */ async function foo() {}", + "class Foo { /* async */ async bar() {} }", ]; Tester::new(NoAsyncAwait::NAME, NoAsyncAwait::PLUGIN, pass, fail).test_and_snapshot(); diff --git a/crates/oxc_linter/src/snapshots/oxc_no_async_await.snap b/crates/oxc_linter/src/snapshots/oxc_no_async_await.snap index 3d14b9bb6eaeb..497be43186025 100644 --- a/crates/oxc_linter/src/snapshots/oxc_no_async_await.snap +++ b/crates/oxc_linter/src/snapshots/oxc_no_async_await.snap @@ -91,3 +91,17 @@ source: crates/oxc_linter/src/tester.rs 7 │ } ╰──── help: Remove the `async` keyword + + ⚠ oxc(no-async-await): async is not allowed + ╭─[no_async_await.tsx:1:13] + 1 │ /* async */ async function foo() {} + · ───── + ╰──── + help: Remove the `async` keyword + + ⚠ oxc(no-async-await): async is not allowed + ╭─[no_async_await.tsx:1:25] + 1 │ class Foo { /* async */ async bar() {} } + · ───── + ╰──── + help: Remove the `async` keyword