From 9b70fe943108dc3a10194a225e328fda4076cb13 Mon Sep 17 00:00:00 2001 From: pierrezimmermann Date: Fri, 10 Nov 2023 17:49:56 +0100 Subject: [PATCH] chore: delete custom rule to await user event --- .../break-testing-library-rules.test.tsx | 2 +- packages/eslint-plugin/README.md | 11 ++--- .../docs/rules/await-user-event.md | 23 --------- packages/eslint-plugin/lib/configs/tests.js | 1 - .../lib/rules/await-user-event.js | 49 ------------------- 5 files changed, 5 insertions(+), 81 deletions(-) delete mode 100644 packages/eslint-plugin/docs/rules/await-user-event.md delete mode 100644 packages/eslint-plugin/lib/rules/await-user-event.js diff --git a/example-app/eslint-breaking-examples/break-testing-library-rules.test.tsx b/example-app/eslint-breaking-examples/break-testing-library-rules.test.tsx index 2a7130f..b9606d1 100644 --- a/example-app/eslint-breaking-examples/break-testing-library-rules.test.tsx +++ b/example-app/eslint-breaking-examples/break-testing-library-rules.test.tsx @@ -3,7 +3,7 @@ import { fireEvent, userEvent } from "@testing-library/react-native"; // This should trigger an error breaking eslint-testing-library rule: // testing-library/no-await-sync-events -// @bam.tech/await-user-event +// @typescript-eslint/no-floating-promises it("a test", async () => { await fireEvent(); 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 "); - }, - }); - } - } - }, - }; - }, -};