-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathawait-user-event.js
More file actions
49 lines (46 loc) · 1.34 KB
/
await-user-event.js
File metadata and controls
49 lines (46 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* @fileoverview Makes sure userEvent.press and userEvent.type are awaited
* @author Pierre Zimmermann
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: "problem",
docs: {
description: "Enforces awaiting userEvent calls",
category: "Possible Errors",
recommended: true,
url: "https://github.com/bamlab/react-native-project-config/tree/main/packages/eslint-plugin/docs/rules/await-user-event.md",
},
messages: {
missingAwait: "userEvent calls should be preceded by 'await'.",
},
schema: [],
fixable: "code",
},
create(context) {
return {
CallExpression(node) {
if (
node.callee.type === "MemberExpression" &&
node.callee.object.name === "userEvent"
) {
// Check if the parent is not an AwaitExpression
if (node.parent.type !== "AwaitExpression") {
context.report({
node,
messageId: "missingAwait",
fix(fixer) {
return fixer.insertTextBefore(node, "await ");
},
});
}
}
},
};
},
};