]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/require-await.js
2 * @fileoverview Rule to disallow async functions which have no `await` expression.
3 * @author Toru Nagashima
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const astUtils
= require("./utils/ast-utils");
14 //------------------------------------------------------------------------------
16 //------------------------------------------------------------------------------
19 * Capitalize the 1st letter of the given text.
20 * @param {string} text The text to capitalize.
21 * @returns {string} The text that the 1st letter was capitalized.
23 function capitalizeFirstLetter(text
) {
24 return text
[0].toUpperCase() + text
.slice(1);
27 //------------------------------------------------------------------------------
29 //------------------------------------------------------------------------------
31 /** @type {import('../shared/types').Rule} */
37 description
: "Disallow async functions which have no `await` expression",
39 url
: "https://eslint.org/docs/rules/require-await"
45 missingAwait
: "{{name}} has no 'await' expression."
50 const sourceCode
= context
.getSourceCode();
54 * Push the scope info object to the stack.
57 function enterFunction() {
65 * Pop the top scope info object from the stack.
66 * Also, it reports the function if needed.
67 * @param {ASTNode} node The node to report.
70 function exitFunction(node
) {
71 if (!node
.generator
&& node
.async
&& !scopeInfo
.hasAwait
&& !astUtils
.isEmptyFunction(node
)) {
74 loc
: astUtils
.getFunctionHeadLoc(node
, sourceCode
),
75 messageId
: "missingAwait",
77 name
: capitalizeFirstLetter(
78 astUtils
.getFunctionNameWithKind(node
)
84 scopeInfo
= scopeInfo
.upper
;
88 FunctionDeclaration
: enterFunction
,
89 FunctionExpression
: enterFunction
,
90 ArrowFunctionExpression
: enterFunction
,
91 "FunctionDeclaration:exit": exitFunction
,
92 "FunctionExpression:exit": exitFunction
,
93 "ArrowFunctionExpression:exit": exitFunction
,
100 scopeInfo
.hasAwait
= true;
102 ForOfStatement(node
) {
108 scopeInfo
.hasAwait
= true;