]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/require-yield.js
aba06140672d6a6058e776c45b4733ebb309155d
2 * @fileoverview Rule to flag the generator functions that does not have yield.
3 * @author Toru Nagashima
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 /** @type {import('../shared/types').Rule} */
18 description
: "require generator functions to contain `yield`",
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;