Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions crates/oxc_linter/src/rules/oxc/no_async_await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions crates/oxc_linter/src/snapshots/oxc_no_async_await.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading