diff --git a/README.md b/README.md index a787ab5..70cdb0d 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,8 @@ These rules enforce some of the [best practices recommended for using Cypress](h In the following sections, different examples of possible configuration file contents are given, together with some brief explanations. Adapt these examples according to your needs. +The examples use the `defineConfig()` helper, introduced with ESLint [9.22.0](https://eslint.org/blog/2025/03/eslint-v9.22.0-released/). Refer to the blog article [Evolving flat config with extends](https://eslint.org/blog/2025/03/flat-config-extends-define-config-global-ignores/) for background information. If you are using ESLint `<9.22.0`, import `defineConfig` from [@eslint/config-helpers](https://www.npmjs.com/package/@eslint/config-helpers) instead of from `eslint/config`. + ### Cypress All rules are available by importing from `eslint-plugin-cypress` and can be individually activated. @@ -82,8 +84,9 @@ All rules are available by importing from `eslint-plugin-cypress` and can be ind - [cypress/unsafe-to-chain-command](https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/unsafe-to-chain-command.md) is activated and set to `error` ```js +import { defineConfig } from 'eslint/config' import pluginCypress from 'eslint-plugin-cypress' -export default [ +export default defineConfig([ { plugins: { cypress: pluginCypress, @@ -92,7 +95,7 @@ export default [ 'cypress/unsafe-to-chain-command': 'error', }, }, -] +]) ``` ### Cypress recommended @@ -102,15 +105,19 @@ The `eslint-plugin-cypress` [recommended rules](#rules) `configs.recommended` ar - [cypress/no-unnecessary-waiting](https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-unnecessary-waiting.md) which is set to `off` ```js +import { defineConfig } from 'eslint/config' import pluginCypress from 'eslint-plugin-cypress' -export default [ - pluginCypress.configs.recommended, +export default defineConfig([ { + files: ['cypress/**/*.js'], + extends: [ + pluginCypress.configs.recommended, + ], rules: { 'cypress/no-unnecessary-waiting': 'off', }, }, -] +]) ``` ### Cypress globals @@ -118,8 +125,16 @@ export default [ The `configs.globals` are activated. ```js +import { defineConfig } from 'eslint/config' import pluginCypress from 'eslint-plugin-cypress' -export default [pluginCypress.configs.globals] +export default defineConfig([ + { + files: ['cypress/**/*.js'], + extends: [ + pluginCypress.configs.globals, + ], + }, +]) ``` ## Disable rules @@ -187,12 +202,16 @@ npm install eslint-plugin-mocha@^11 --save-dev ``` ```js +import { defineConfig } from 'eslint/config' import pluginMocha from 'eslint-plugin-mocha' import pluginCypress from 'eslint-plugin-cypress' -export default [ - pluginMocha.configs.recommended, - pluginCypress.configs.recommended, +export default defineConfig([ { + files: ['cypress/**/*.js'], + extends: [ + pluginMocha.configs.recommended, + pluginCypress.configs.recommended, + ], rules: { 'mocha/no-exclusive-tests': 'error', 'mocha/no-pending-tests': 'error', @@ -200,7 +219,7 @@ export default [ 'cypress/no-unnecessary-waiting': 'off', }, }, -] +]) ``` ### Cypress and Chai recommended @@ -216,17 +235,21 @@ npm install eslint-plugin-chai-friendly@^1.0.1 --save-dev ``` ```js +import { defineConfig } from 'eslint/config' import pluginCypress from 'eslint-plugin-cypress' import pluginChaiFriendly from 'eslint-plugin-chai-friendly' -export default [ - pluginCypress.configs.recommended, - pluginChaiFriendly.configs.recommendedFlat, +export default defineConfig([ { + files: ['cypress/**/*.js'], + extends: [ + pluginCypress.configs.recommended, + pluginChaiFriendly.configs.recommendedFlat, + ], rules: { 'cypress/no-unnecessary-waiting': 'off', }, }, -] +]) ``` ## Contributing diff --git a/circle.yml b/circle.yml index 6ffc3ce..750b864 100644 --- a/circle.yml +++ b/circle.yml @@ -17,13 +17,12 @@ workflows: matrix: parameters: eslint-version: ['9'] - config-file: [ - # configurations correspond to examples in README - 'default', - 'default-deprecated', # using deprecated /flat - 'recommended', - 'globals', - ] + config-file: + # configurations correspond to examples in README + - 'globals' + - 'one-rule-deprecated' # using deprecated /flat + - 'one-rule' + - 'recommended' requires: - build-test-project - release: diff --git a/eslint.config.mjs b/eslint.config.mjs index 85ee80a..1fe8aaa 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,24 +1,22 @@ +import { defineConfig, globalIgnores } from 'eslint/config' import globals from 'globals' import pluginJs from '@eslint/js' import eslintPlugin from 'eslint-plugin-eslint-plugin' import mochaPlugin from 'eslint-plugin-mocha' import stylistic from '@stylistic/eslint-plugin' -export default [ - pluginJs.configs.recommended, - eslintPlugin.configs.recommended, - mochaPlugin.configs.recommended, - stylistic.configs.recommended, +export default defineConfig([ + + globalIgnores(['test-project/**/*', '!test-project/**/eslint*']), + { - ignores: [ - 'test-project/**/*', - '!test-project/**/eslint*', + files: ['**/*.{,m}js'], + extends: [ + pluginJs.configs.recommended, + eslintPlugin.configs.recommended, + mochaPlugin.configs.recommended, + stylistic.configs.recommended, ], - }, - { - languageOptions: { - globals: globals.node, - }, rules: { 'no-redeclare': 'off', '@stylistic/arrow-parens': ['error', 'always'], @@ -34,5 +32,8 @@ export default [ 'mocha/no-mocha-arrows': 'off', 'mocha/no-setup-in-describe': 'off', }, + languageOptions: { + globals: globals.node, + }, }, -] +]) diff --git a/test-project/eslint-configs/eslint.default-deprecated.mjs b/test-project/eslint-configs/eslint.default-deprecated.mjs deleted file mode 100644 index d08fc66..0000000 --- a/test-project/eslint-configs/eslint.default-deprecated.mjs +++ /dev/null @@ -1,11 +0,0 @@ -// eslint-plugin-cypress/flat is deprecated and is identical to -// eslint-plugin-cypress -import pluginCypress from 'eslint-plugin-cypress/flat' -export default [ - pluginCypress.configs.recommended, - { - rules: { - 'cypress/no-unnecessary-waiting': 'off', - }, - }, -] diff --git a/test-project/eslint-configs/eslint.default.mjs b/test-project/eslint-configs/eslint.default.mjs deleted file mode 100644 index 8a43cb4..0000000 --- a/test-project/eslint-configs/eslint.default.mjs +++ /dev/null @@ -1,9 +0,0 @@ -import pluginCypress from 'eslint-plugin-cypress' -export default [ - pluginCypress.configs.recommended, - { - rules: { - 'cypress/no-unnecessary-waiting': 'off', - }, - }, -] diff --git a/test-project/eslint-configs/eslint.globals.mjs b/test-project/eslint-configs/eslint.globals.mjs index efaa8ea..fca4e0d 100644 --- a/test-project/eslint-configs/eslint.globals.mjs +++ b/test-project/eslint-configs/eslint.globals.mjs @@ -1,2 +1,11 @@ +// Only config.globals are activated +import { defineConfig } from 'eslint/config' import pluginCypress from 'eslint-plugin-cypress' -export default [pluginCypress.configs.globals] +export default defineConfig([ + { + files: ['cypress/**/*.js'], + extends: [ + pluginCypress.configs.globals, + ], + }, +]) diff --git a/test-project/eslint-configs/eslint.one-rule-deprecated.mjs b/test-project/eslint-configs/eslint.one-rule-deprecated.mjs new file mode 100644 index 0000000..c9d1d3c --- /dev/null +++ b/test-project/eslint-configs/eslint.one-rule-deprecated.mjs @@ -0,0 +1,15 @@ +// eslint-plugin-cypress/flat is deprecated and is identical to +// eslint-plugin-cypress +// Plugin activated, only one rule applied +import { defineConfig } from 'eslint/config' +import pluginCypress from 'eslint-plugin-cypress/flat' +export default defineConfig([ + { + plugins: { + cypress: pluginCypress, + }, + rules: { + 'cypress/unsafe-to-chain-command': 'error', + }, + }, +]) diff --git a/test-project/eslint-configs/eslint.one-rule.mjs b/test-project/eslint-configs/eslint.one-rule.mjs new file mode 100644 index 0000000..2ecb64f --- /dev/null +++ b/test-project/eslint-configs/eslint.one-rule.mjs @@ -0,0 +1,13 @@ +// Plugin activated, only one rule applied +import { defineConfig } from 'eslint/config' +import pluginCypress from 'eslint-plugin-cypress' +export default defineConfig([ + { + plugins: { + cypress: pluginCypress, + }, + rules: { + 'cypress/unsafe-to-chain-command': 'error', + }, + }, +]) diff --git a/test-project/eslint-configs/eslint.recommended.mjs b/test-project/eslint-configs/eslint.recommended.mjs index 8a43cb4..2fba405 100644 --- a/test-project/eslint-configs/eslint.recommended.mjs +++ b/test-project/eslint-configs/eslint.recommended.mjs @@ -1,9 +1,14 @@ +// All recommended rules are applied, except cypress/no-unnecessary-waiting +import { defineConfig } from 'eslint/config' import pluginCypress from 'eslint-plugin-cypress' -export default [ - pluginCypress.configs.recommended, +export default defineConfig([ { + files: ['cypress/**/*.js'], + extends: [ + pluginCypress.configs.recommended, + ], rules: { 'cypress/no-unnecessary-waiting': 'off', }, }, -] +]) diff --git a/test-project/eslint.config.mjs b/test-project/eslint.config.mjs index 5d45473..3043aee 100644 --- a/test-project/eslint.config.mjs +++ b/test-project/eslint.config.mjs @@ -1,9 +1,13 @@ -import pluginCypress from 'eslint-plugin-cypress/flat' -export default [ - pluginCypress.configs.recommended, +// All recommended rules are applied, except cypress/no-unnecessary-waiting +import { defineConfig } from 'eslint/config' +import pluginCypress from 'eslint-plugin-cypress' +export default defineConfig([ { + extends: [ + pluginCypress.configs.recommended, + ], rules: { 'cypress/no-unnecessary-waiting': 'off', }, }, -] +])