2 * @fileoverview Rule to flag the generator functions that does not have yield.
3 * @author Toru Nagashima
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
17 description: "require generator functions to contain `yield`",
18 category: "ECMAScript 6",
20 url: "https://eslint.org/docs/rules/require-yield"
26 missingYield: "This generator function does not have 'yield'."
34 * If the node is a generator function, start counting `yield` keywords.
35 * @param {Node} node A function node to check.
38 function beginChecking(node) {
45 * If the node is a generator function, end counting `yield` keywords, then
47 * @param {Node} node A function node to check.
50 function endChecking(node) {
51 if (!node.generator) {
55 const countYield = stack.pop();
57 if (countYield === 0 && node.body.body.length > 0) {
58 context.report({ node, messageId: "missingYield" });
63 FunctionDeclaration: beginChecking,
64 "FunctionDeclaration:exit": endChecking,
65 FunctionExpression: beginChecking,
66 "FunctionExpression:exit": endChecking,
68 // Increases the count of `yield` keyword.
71 /* istanbul ignore else */
72 if (stack.length > 0) {
73 stack[stack.length - 1] += 1;