{"record":{"id":"ceb9c39b04ab0a90","repo":"oxc-project/oxc","slug":"this-generator-function-does-not-have-yield","errorCode":null,"errorMessage":"This generator function does not have `yield`","messagePattern":"This generator function does not have `yield`","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/require_yield.rs","lineNumber":14,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{ArrowFunctionExpression, Function, YieldExpression},\n};\nuse oxc_ast_visit::VisitJs;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse oxc_syntax::scope::ScopeFlags;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn require_yield_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"This generator function does not have `yield`\")\n        .with_help(\"Add a `yield` expression inside the generator body, or convert it to a regular function if iteration behavior is not needed.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct RequireYield;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// This rule generates warnings for generator functions that do not have the yield keyword.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Probably a mistake.\n    ///\n    /// ### Examples\n    ///","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/require_yield.rs#L1-L32","documentation":"oxlint `eslint/require-yield`: a generator function (`function*`) contains no `yield` expression, which per the rule's doc block makes the generator misleading — it produces values only from `return` and its body runs lazily. `require_yield_diagnostic` (require_yield.rs:14) suggests adding a `yield` or converting to a regular function. Nested generators are tracked separately via ScopeFlags, so a yield in an inner function does not count for the outer one.","triggerScenarios":"`function* emptyGen() { console.log('hi'); }` — any Function or arrow-style generator whose own body has no YieldExpression. Includes generators delegating only via `yield*`? No: `yield*` is a yield expression and satisfies the rule; only truly yield-free generators are flagged.","commonSituations":"Saga-style functions refactored until all yields were removed; scaffolding for an iterator protocol where the generator marker was left behind; copy-paste of a generator shell.","solutions":["Remove the `*` so it is a plain function if iteration is not needed.","Add the intended `yield` (or `yield*` delegation) if the generator is incomplete.","If the shape must stay (e.g. library contract requiring an iterator), suppress with `// oxlint-disable-next-line require-yield`."],"exampleFix":"// before\nfunction* loadItems() {\n  return [];\n}\n\n// after\nfunction loadItems() {\n  return [];\n}","handlingStrategy":"validation","validationCode":"# generators with no yield (heuristic)\nrg -n --pcre2 'function\\s*\\*[^{]*\\{(?:(?!yield)[^}])*\\}' src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add the `*` only when the function actually yields; remove it during refactors that strip all yields.","Remember `yield*` delegation counts as a yield for this rule.","Run oxlint after generator refactors — require-yield catches leftovers immediately."],"tags":["eslint","oxlint","generators","lint"],"backgroundTag":"generator-without-yield","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}