]>
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 //------------------------------------------------------------------------------
36 description
: "disallow async functions which have no `await` expression",
38 url
: "https://eslint.org/docs/rules/require-await"
44 missingAwait
: "{{name}} has no 'await' expression."
49 const sourceCode
= context
.getSourceCode();
53 * Push the scope info object to the stack.
56 function enterFunction() {
64 * Pop the top scope info object from the stack.
65 * Also, it reports the function if needed.
66 * @param {ASTNode} node The node to report.
69 function exitFunction(node
) {
70 if (!node
.generator
&& node
.async
&& !scopeInfo
.hasAwait
&& !astUtils
.isEmptyFunction(node
)) {
73 loc
: astUtils
.getFunctionHeadLoc(node
, sourceCode
),
74 messageId
: "missingAwait",
76 name
: capitalizeFirstLetter(
77 astUtils
.getFunctionNameWithKind(node
)
83 scopeInfo
= scopeInfo
.upper
;
87 FunctionDeclaration
: enterFunction
,
88 FunctionExpression
: enterFunction
,
89 ArrowFunctionExpression
: enterFunction
,
90 "FunctionDeclaration:exit": exitFunction
,
91 "FunctionExpression:exit": exitFunction
,
92 "ArrowFunctionExpression:exit": exitFunction
,
99 scopeInfo
.hasAwait
= true;
101 ForOfStatement(node
) {
107 scopeInfo
.hasAwait
= true;