diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index 7aef838..460ce85 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -102,15 +102,12 @@ This plugin exports some custom rules that you can optionally use in your projec -๐Ÿ’ผ Configurations enabled in.\ -๐Ÿงช Set in the `tests` configuration.\ ๐Ÿ”ง Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix). -| Name | Description | ๐Ÿ’ผ | ๐Ÿ”ง | -| :------------------------------------------------------------------------------------------------------------------------------------------------ | :----------------------------------------------------- | :-- | :-- | -| [await-user-event](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/await-user-event.md) | Enforces awaiting userEvent calls | ๐Ÿงช | ๐Ÿ”ง | -| [prefer-user-event](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/prefer-user-event.md) | Enforces usage of userEvent over fireEvent in tests. | | ๐Ÿ”ง | -| [require-named-effect](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/require-named-effect.md) | Enforces the use of named functions inside a useEffect | | | +| Name | Description | ๐Ÿ”ง | +| :------------------------------------------------------------------------------------------------------------------------------------------------ | :----------------------------------------------------- | :-- | +| [prefer-user-event](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/prefer-user-event.md) | Enforces usage of userEvent over fireEvent in tests. | ๐Ÿ”ง | +| [require-named-effect](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/require-named-effect.md) | Enforces the use of named functions inside a useEffect | | diff --git a/packages/eslint-plugin/docs/rules/await-user-event.md b/packages/eslint-plugin/docs/rules/await-user-event.md deleted file mode 100644 index 03ef9e3..0000000 --- a/packages/eslint-plugin/docs/rules/await-user-event.md +++ /dev/null @@ -1,23 +0,0 @@ -# Enforces awaiting userEvent calls (`@bam.tech/await-user-event`) - -๐Ÿ’ผ This rule is enabled in the ๐Ÿงช `tests` config. - -๐Ÿ”ง This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). - - - -Makes sure calls to `userEvent` APIs are awaited - -## Rule details - -Examples of **incorrect** code for this rule: - -```jsx -userEvent.press(button); -``` - -Examples of **correct** code for this rule: - -```jsx -await userEvent.press(button); -``` diff --git a/packages/eslint-plugin/lib/configs/tests.js b/packages/eslint-plugin/lib/configs/tests.js index 40e7e68..5516eb4 100644 --- a/packages/eslint-plugin/lib/configs/tests.js +++ b/packages/eslint-plugin/lib/configs/tests.js @@ -45,6 +45,5 @@ module.exports = defineConfig({ "testing-library/prefer-presence-queries": "error", "testing-library/no-wait-for-side-effects": "error", "testing-library/prefer-screen-queries": "error", - "@bam.tech/await-user-event": "error", }, }); diff --git a/packages/eslint-plugin/lib/rules/await-user-event.js b/packages/eslint-plugin/lib/rules/await-user-event.js deleted file mode 100644 index fea9633..0000000 --- a/packages/eslint-plugin/lib/rules/await-user-event.js +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @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 "); - }, - }); - } - } - }, - }; - }, -};