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"
30 * If the node is a generator function, start counting `yield` keywords.
31 * @param {Node} node A function node to check.
34 function beginChecking(node) {
41 * If the node is a generator function, end counting `yield` keywords, then
43 * @param {Node} node A function node to check.
46 function endChecking(node) {
47 if (!node.generator) {
51 const countYield = stack.pop();
53 if (countYield === 0 && node.body.body.length > 0) {
54 context.report({ node, message: "This generator function does not have 'yield'." });
59 FunctionDeclaration: beginChecking,
60 "FunctionDeclaration:exit": endChecking,
61 FunctionExpression: beginChecking,
62 "FunctionExpression:exit": endChecking,
64 // Increases the count of `yield` keyword.
67 /* istanbul ignore else */
68 if (stack.length > 0) {
69 stack[stack.length - 1] += 1;