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
22 changes: 21 additions & 1 deletion crates/oxc_linter/src/rules/eslint/require_await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,15 @@ impl Rule for RequireAwait {
span, key, ..
}) = parent_parent_node
{
let need_delete_span = get_delete_span(ctx, span.start);
let need_delete_span = get_delete_span(
ctx,
if matches!(parent_parent_node, AstKind::ObjectProperty(x) if !x.method)
{
func.span.start
} else {
span.start
},
);
let check_span = if matches!(key, PropertyKey::StaticIdentifier(_))
{
key.span()
Expand Down Expand Up @@ -153,6 +161,17 @@ impl Rule for RequireAwait {
fn get_delete_span(ctx: &LintContext, start: u32) -> Span {
let end = start + 5;
let async_key_span = Span::new(start, end);

// debug assertions
#[cfg(debug_assertions)]
{
assert!(
async_key_span.source_text(ctx.source_text()) == "async",
"Expected 'async' at span {async_key_span:?}, found: {:?}",
async_key_span.source_text(ctx.source_text())
);
}

let mut offset: u32 = 0;
for c in ctx.source_text()[(end as usize)..].chars() {
if !c.is_whitespace() {
Expand Down Expand Up @@ -284,6 +303,7 @@ fn test() {
"let a = { c: () => { let c }, t:()=>{ let r } }",
),
("async function O(){r}", "function O(){r}"),
("s={expoí:async function(){{}}}", "s={expoí:function(){{}}}"),
];

Tester::new(RequireAwait::NAME, RequireAwait::PLUGIN, pass, fail)
Expand Down
Loading