Skip to content

Commit 9015c2e

Browse files
authored
chore(docs): update documents and example to use defineConfig() (#277)
1 parent 47d0a20 commit 9015c2e

File tree

10 files changed

+112
-63
lines changed

10 files changed

+112
-63
lines changed

README.md

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,18 @@ These rules enforce some of the [best practices recommended for using Cypress](h
7575

7676
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.
7777

78+
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`.
79+
7880
### Cypress
7981

8082
All rules are available by importing from `eslint-plugin-cypress` and can be individually activated.
8183

8284
- [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`
8385

8486
```js
87+
import { defineConfig } from 'eslint/config'
8588
import pluginCypress from 'eslint-plugin-cypress'
86-
export default [
89+
export default defineConfig([
8790
{
8891
plugins: {
8992
cypress: pluginCypress,
@@ -92,7 +95,7 @@ export default [
9295
'cypress/unsafe-to-chain-command': 'error',
9396
},
9497
},
95-
]
98+
])
9699
```
97100

98101
### Cypress recommended
@@ -102,24 +105,36 @@ The `eslint-plugin-cypress` [recommended rules](#rules) `configs.recommended` ar
102105
- [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`
103106

104107
```js
108+
import { defineConfig } from 'eslint/config'
105109
import pluginCypress from 'eslint-plugin-cypress'
106-
export default [
107-
pluginCypress.configs.recommended,
110+
export default defineConfig([
108111
{
112+
files: ['cypress/**/*.js'],
113+
extends: [
114+
pluginCypress.configs.recommended,
115+
],
109116
rules: {
110117
'cypress/no-unnecessary-waiting': 'off',
111118
},
112119
},
113-
]
120+
])
114121
```
115122

116123
### Cypress globals
117124

118125
The `configs.globals` are activated.
119126

120127
```js
128+
import { defineConfig } from 'eslint/config'
121129
import pluginCypress from 'eslint-plugin-cypress'
122-
export default [pluginCypress.configs.globals]
130+
export default defineConfig([
131+
{
132+
files: ['cypress/**/*.js'],
133+
extends: [
134+
pluginCypress.configs.globals,
135+
],
136+
},
137+
])
123138
```
124139

125140
## Disable rules
@@ -187,20 +202,24 @@ npm install eslint-plugin-mocha@^11 --save-dev
187202
```
188203

189204
```js
205+
import { defineConfig } from 'eslint/config'
190206
import pluginMocha from 'eslint-plugin-mocha'
191207
import pluginCypress from 'eslint-plugin-cypress'
192-
export default [
193-
pluginMocha.configs.recommended,
194-
pluginCypress.configs.recommended,
208+
export default defineConfig([
195209
{
210+
files: ['cypress/**/*.js'],
211+
extends: [
212+
pluginMocha.configs.recommended,
213+
pluginCypress.configs.recommended,
214+
],
196215
rules: {
197216
'mocha/no-exclusive-tests': 'error',
198217
'mocha/no-pending-tests': 'error',
199218
'mocha/no-mocha-arrows': 'off',
200219
'cypress/no-unnecessary-waiting': 'off',
201220
},
202221
},
203-
]
222+
])
204223
```
205224

206225
### Cypress and Chai recommended
@@ -216,17 +235,21 @@ npm install eslint-plugin-chai-friendly@^1.0.1 --save-dev
216235
```
217236

218237
```js
238+
import { defineConfig } from 'eslint/config'
219239
import pluginCypress from 'eslint-plugin-cypress'
220240
import pluginChaiFriendly from 'eslint-plugin-chai-friendly'
221-
export default [
222-
pluginCypress.configs.recommended,
223-
pluginChaiFriendly.configs.recommendedFlat,
241+
export default defineConfig([
224242
{
243+
files: ['cypress/**/*.js'],
244+
extends: [
245+
pluginCypress.configs.recommended,
246+
pluginChaiFriendly.configs.recommendedFlat,
247+
],
225248
rules: {
226249
'cypress/no-unnecessary-waiting': 'off',
227250
},
228251
},
229-
]
252+
])
230253
```
231254

232255
## Contributing

circle.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ workflows:
1717
matrix:
1818
parameters:
1919
eslint-version: ['9']
20-
config-file: [
21-
# configurations correspond to examples in README
22-
'default',
23-
'default-deprecated', # using deprecated /flat
24-
'recommended',
25-
'globals',
26-
]
20+
config-file:
21+
# configurations correspond to examples in README
22+
- 'globals'
23+
- 'one-rule-deprecated' # using deprecated /flat
24+
- 'one-rule'
25+
- 'recommended'
2726
requires:
2827
- build-test-project
2928
- release:

eslint.config.mjs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1+
import { defineConfig, globalIgnores } from 'eslint/config'
12
import globals from 'globals'
23
import pluginJs from '@eslint/js'
34
import eslintPlugin from 'eslint-plugin-eslint-plugin'
45
import mochaPlugin from 'eslint-plugin-mocha'
56
import stylistic from '@stylistic/eslint-plugin'
67

7-
export default [
8-
pluginJs.configs.recommended,
9-
eslintPlugin.configs.recommended,
10-
mochaPlugin.configs.recommended,
11-
stylistic.configs.recommended,
8+
export default defineConfig([
9+
10+
globalIgnores(['test-project/**/*', '!test-project/**/eslint*']),
11+
1212
{
13-
ignores: [
14-
'test-project/**/*',
15-
'!test-project/**/eslint*',
13+
files: ['**/*.{,m}js'],
14+
extends: [
15+
pluginJs.configs.recommended,
16+
eslintPlugin.configs.recommended,
17+
mochaPlugin.configs.recommended,
18+
stylistic.configs.recommended,
1619
],
17-
},
18-
{
19-
languageOptions: {
20-
globals: globals.node,
21-
},
2220
rules: {
2321
'no-redeclare': 'off',
2422
'@stylistic/arrow-parens': ['error', 'always'],
@@ -34,5 +32,8 @@ export default [
3432
'mocha/no-mocha-arrows': 'off',
3533
'mocha/no-setup-in-describe': 'off',
3634
},
35+
languageOptions: {
36+
globals: globals.node,
37+
},
3738
},
38-
]
39+
])

test-project/eslint-configs/eslint.default-deprecated.mjs

Lines changed: 0 additions & 11 deletions
This file was deleted.

test-project/eslint-configs/eslint.default.mjs

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1+
// Only config.globals are activated
2+
import { defineConfig } from 'eslint/config'
13
import pluginCypress from 'eslint-plugin-cypress'
2-
export default [pluginCypress.configs.globals]
4+
export default defineConfig([
5+
{
6+
files: ['cypress/**/*.js'],
7+
extends: [
8+
pluginCypress.configs.globals,
9+
],
10+
},
11+
])
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// eslint-plugin-cypress/flat is deprecated and is identical to
2+
// eslint-plugin-cypress
3+
// Plugin activated, only one rule applied
4+
import { defineConfig } from 'eslint/config'
5+
import pluginCypress from 'eslint-plugin-cypress/flat'
6+
export default defineConfig([
7+
{
8+
plugins: {
9+
cypress: pluginCypress,
10+
},
11+
rules: {
12+
'cypress/unsafe-to-chain-command': 'error',
13+
},
14+
},
15+
])
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Plugin activated, only one rule applied
2+
import { defineConfig } from 'eslint/config'
3+
import pluginCypress from 'eslint-plugin-cypress'
4+
export default defineConfig([
5+
{
6+
plugins: {
7+
cypress: pluginCypress,
8+
},
9+
rules: {
10+
'cypress/unsafe-to-chain-command': 'error',
11+
},
12+
},
13+
])
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
// All recommended rules are applied, except cypress/no-unnecessary-waiting
2+
import { defineConfig } from 'eslint/config'
13
import pluginCypress from 'eslint-plugin-cypress'
2-
export default [
3-
pluginCypress.configs.recommended,
4+
export default defineConfig([
45
{
6+
files: ['cypress/**/*.js'],
7+
extends: [
8+
pluginCypress.configs.recommended,
9+
],
510
rules: {
611
'cypress/no-unnecessary-waiting': 'off',
712
},
813
},
9-
]
14+
])

test-project/eslint.config.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import pluginCypress from 'eslint-plugin-cypress/flat'
2-
export default [
3-
pluginCypress.configs.recommended,
1+
// All recommended rules are applied, except cypress/no-unnecessary-waiting
2+
import { defineConfig } from 'eslint/config'
3+
import pluginCypress from 'eslint-plugin-cypress'
4+
export default defineConfig([
45
{
6+
extends: [
7+
pluginCypress.configs.recommended,
8+
],
59
rules: {
610
'cypress/no-unnecessary-waiting': 'off',
711
},
812
},
9-
]
13+
])

0 commit comments

Comments
 (0)