mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(linter): AllowFunction doesn't support generator (#2277)
This commit is contained in:
parent
3cb85778bc
commit
37a2676e1e
1 changed files with 6 additions and 10 deletions
|
|
@ -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![
|
||||
|
|
|
|||
Loading…
Reference in a new issue