fix(linter): AllowFunction doesn't support generator (#2277)

This commit is contained in:
Dunqing 2024-02-02 21:53:44 +08:00 committed by GitHub
parent 3cb85778bc
commit 37a2676e1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -43,19 +43,14 @@ impl Rule for RequireYield {
return; return;
} }
let span = match kind { if let AstKind::Function(func) = kind {
AstKind::Function(func) if func.generator && func.body.as_ref().is_some_and(|body| !body.statements.is_empty())
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);
}
AstKind::ArrowExpression(arrow) if !arrow.body.statements.is_empty() => arrow.span,
_ => return,
};
ctx.diagnostic(RequireYieldDiagnostic(span)); ctx.diagnostic(RequireYieldDiagnostic(span));
} }
}
}
} }
#[test] #[test]
@ -72,6 +67,7 @@ fn test() {
("var obj = { *foo() { } };", None), ("var obj = { *foo() { } };", None),
("class A { *foo() { yield 0; } };", None), ("class A { *foo() { yield 0; } };", None),
("class A { *foo() { } };", None), ("class A { *foo() { } };", None),
("() => {}", None),
]; ];
let fail = vec![ let fail = vec![