From 37a2676e1ea708b00b7dc5381cab361c2d6e1791 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Fri, 2 Feb 2024 21:53:44 +0800 Subject: [PATCH] fix(linter): AllowFunction doesn't support generator (#2277) --- .../oxc_linter/src/rules/eslint/require_yield.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/crates/oxc_linter/src/rules/eslint/require_yield.rs b/crates/oxc_linter/src/rules/eslint/require_yield.rs index d1f375db1..de67d957d 100644 --- a/crates/oxc_linter/src/rules/eslint/require_yield.rs +++ b/crates/oxc_linter/src/rules/eslint/require_yield.rs @@ -43,18 +43,13 @@ impl Rule for RequireYield { return; } - let span = match kind { - AstKind::Function(func) - if func.generator - && func.body.as_ref().is_some_and(|body| !body.statements.is_empty()) => + if let AstKind::Function(func) = kind { + if func.generator && func.body.as_ref().is_some_and(|body| !body.statements.is_empty()) { - func.id.as_ref().map_or_else(|| kind.span(), |ident| ident.span) + let span = func.id.as_ref().map_or_else(|| kind.span(), |ident| ident.span); + ctx.diagnostic(RequireYieldDiagnostic(span)); } - AstKind::ArrowExpression(arrow) if !arrow.body.statements.is_empty() => arrow.span, - _ => return, - }; - - ctx.diagnostic(RequireYieldDiagnostic(span)); + } } } @@ -72,6 +67,7 @@ fn test() { ("var obj = { *foo() { } };", None), ("class A { *foo() { yield 0; } };", None), ("class A { *foo() { } };", None), + ("() => {}", None), ]; let fail = vec![