From 07899f83063a25031e192673402487a5e8a39483 Mon Sep 17 00:00:00 2001 From: Adam DeHaven Date: Wed, 5 Jun 2024 13:31:21 -0400 Subject: [PATCH] feat: cypress config --- README.md | 25 ++++++++++++++++++++++++- configs/cypress.mjs | 24 ++++++++++++++++++++++++ configs/index.mjs | 23 ----------------------- package.json | 1 + 4 files changed, 49 insertions(+), 24 deletions(-) create mode 100644 configs/cypress.mjs diff --git a/README.md b/README.md index a7d7a45..7bc9d5d 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,6 @@ The default config provides linting for files matching this pattern `**/*.{js,mj - TypeScript recommended rules - `eslint-plugin-vue` - `eslint-plugin-promise` -- `eslint-plugin-cypress` - [ESLint Stylistic](https://eslint.style/) rules configured for our preferred formatting settings - ...and more. See [`index.mjs`](./configs/index.mjs) to view the configuration. @@ -68,6 +67,19 @@ import eslintKongUiConfigJson from '@kong/eslint-config-kong-ui/json' > [!Note] > You will likely only want to apply the JSON config to a subset of file patterns in your project. See the section on [applying a config to a subset of files](#apply-a-config-to-a-subset-of-files) for detailed instructions. +#### Cypress config + +The Cypress config provides linting for Cypress test files, given a pattern for `files` that your **host project provides**, and includes rules and preferred formatting settings configured via `eslint-plugin-cypress`, as well as the ESLint and TypeScript ESLint recommended settings. See [`cypress.mjs`](./configs/cypress.mjs) to view the configuration. + +The Cypress config can be imported as shown here: + +```javascript +import eslintKongUiConfigCypress from '@kong/eslint-config-kong-ui/cypress' +``` + +> [!Note] +> You will likely only want to apply the Cypress config to a subset of file patterns in your project. See the section on [applying a config to a subset of files](#apply-a-config-to-a-subset-of-files) for detailed instructions. + ### Setup To use the shared config, import the package inside of an `eslint.config.mjs` file and add it into the exported array, like this: @@ -110,6 +122,7 @@ For example, you may only want to apply the [JSON config](#json-config) to `**/l // eslint.config.mjs import eslintKongUiConfig from '@kong/eslint-config-kong-ui' import eslintKongUiConfigJson from '@kong/eslint-config-kong-ui/json' +import eslintKongUiConfigCypress from '@kong/eslint-config-kong-ui/cypress' export default [ // Use the main config for all other files @@ -119,6 +132,16 @@ export default [ ...config, files: ['**/locales/**/*.json'] })), + // Only apply the shared Cypress config to files that match the given pattern + ...eslintKongUiConfigCypress.map(config => ({ + ...config, + files: [ + '**/*.cy.ts', + '**/cypress/**', + 'cypress/integration/**.spec.{js,ts,jsx,tsx}', + 'cypress/integration/**.cy.{js,ts,jsx,tsx}', + ] + })), // your modifications { rules: { diff --git a/configs/cypress.mjs b/configs/cypress.mjs new file mode 100644 index 0000000..ab92bc8 --- /dev/null +++ b/configs/cypress.mjs @@ -0,0 +1,24 @@ +import eslint from '@eslint/js' +import tseslint from 'typescript-eslint' + +// Compatibility utils +import { FlatCompat } from '@eslint/eslintrc' +const compat = new FlatCompat() + +export default [ + eslint.configs.recommended, + ...tseslint.configs.recommended, + ...compat.config({ + extends: ['plugin:cypress/recommended'], + }), + { + ...compat.config({ + extends: ['plugin:cypress/recommended'], + }), + rules: { + 'promise/always-return': 'off', + 'promise/catch-or-return': 'off', + 'promise/no-nesting': 'off', + }, + }, +] diff --git a/configs/index.mjs b/configs/index.mjs index 794c29b..473d8fa 100644 --- a/configs/index.mjs +++ b/configs/index.mjs @@ -20,9 +20,6 @@ export default [ extends: ['plugin:promise/recommended'], }), ), - ...compat.config({ - extends: ['plugin:cypress/recommended'], - }), // Global ignores { ignores: [ @@ -136,24 +133,4 @@ export default [ ], }, }, - { - files: [ - '**/*.cy.ts', - '**/cypress/**', - ], - rules: { - 'promise/always-return': 'off', - 'promise/catch-or-return': 'off', - 'promise/no-nesting': 'off', - }, - }, - { - files: [ - 'cypress/integration/**.spec.{js,ts,jsx,tsx}', - 'cypress/integration/**.cy.{js,ts,jsx,tsx}', - ], - ...compat.config({ - extends: ['plugin:cypress/recommended'], - }), - }, ] diff --git a/package.json b/package.json index 4686acd..9f02319 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ ".": "./configs/index.mjs", "./default": "./configs/index.mjs", "./json": "./configs/json.mjs", + "./cypress": "./configs/cypress.mjs", "./package.json": "./package.json", "./dist/*": "./dist/*" },