You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,15 +72,17 @@ This ensures that pnpm installs dependencies in a way that is more compatible wi
72
72
You can configure rules in your `eslint.config.js` files as in this example:
73
73
74
74
```js
75
-
exportdefault [
75
+
import { defineConfig } from"eslint/config";
76
+
77
+
exportdefaultdefineConfig([
76
78
{
77
79
files: ["**/*.js", "**/*.cjs", "**/*.mjs"],
78
80
rules: {
79
81
"prefer-const":"warn",
80
82
"no-constant-binary-expression":"error"
81
83
}
82
84
}
83
-
];
85
+
]);
84
86
```
85
87
86
88
The names `"prefer-const"` and `"no-constant-binary-expression"` are the names of [rules](https://eslint.org/docs/rules) in ESLint. The first value is the error level of the rule and can be one of these values:
Copy file name to clipboardExpand all lines: docs/src/use/configure/combine-configs.md
+49-23Lines changed: 49 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,80 +16,106 @@ If you are importing an object from another module, in most cases, you can just
16
16
```js
17
17
// eslint.config.js
18
18
importjsfrom"@eslint/js";
19
+
import { defineConfig } from"eslint/config";
19
20
20
-
exportdefault [
21
+
exportdefaultdefineConfig([
21
22
js.configs.recommended,
22
23
{
23
24
rules: {
24
25
"no-unused-vars":"warn"
25
26
}
26
27
}
27
-
];
28
+
]);
28
29
```
29
30
30
31
Here, the `js.configs.recommended` predefined configuration is applied first and then another configuration object adds the desired configuration for `no-unused-vars`.
31
32
32
-
### Apply a Config Object to a Subset of Files
33
+
### Apply a Configuration to a Subset of Files
33
34
34
-
You can apply a config object to just a subset of files by creating a new object with a `files` key and using the object spread operator to merge in the rest of the properties from the config object. For example:
35
+
You can apply a config object to just a subset of files by creating a new object with a `files` key and using the `extends` key to merge in the rest of the properties from the config object. For example:
35
36
36
37
```js
37
38
// eslint.config.js
38
39
importjsfrom"@eslint/js";
40
+
import { defineConfig } from"eslint/config";
39
41
40
-
exportdefault [
42
+
exportdefaultdefineConfig([
41
43
{
42
-
...js.configs.recommended,
43
-
files: ["**/src/safe/*.js"]
44
+
files: ["**/src/safe/*.js"],
45
+
plugins: {
46
+
js
47
+
},
48
+
extends: ["js/recommended"]
44
49
}
45
-
];
50
+
]);
46
51
```
47
52
48
-
Here, the `js.configs.recommended` config object is applied only to files that match the pattern "`**/src/safe/*.js"`.
53
+
Here, the `js/recommended` config object is applied only to files that match the pattern "`**/src/safe/*.js"`.
49
54
50
55
## Apply a Config Array
51
56
52
-
If you are importing an array from another module, you can use the array spread operator to insert the items from that array into your exported array. Here's an example:
57
+
If you are importing an array from another module, insert the array directly into your exported array. Here's an example:
53
58
54
59
```js
55
60
// eslint.config.js
56
61
importexampleConfigsfrom"eslint-config-example";
62
+
import { defineConfig } from"eslint/config";
57
63
58
-
exportdefault [
59
-
...exampleConfigs,
64
+
exportdefaultdefineConfig([
65
+
66
+
// insert array directly
67
+
exampleConfigs,
60
68
61
69
// your modifications
62
70
{
63
71
rules: {
64
72
"no-unused-vars":"warn"
65
73
}
66
74
}
67
-
];
75
+
]);
68
76
```
69
77
70
-
Here, the `exampleConfigs` shareable configuration is applied first and then another configuration object adds the desired configuration for `no-unused-vars`.
78
+
Here, the `exampleConfigs` shareable configuration is applied first and then another configuration object adds the desired configuration for `no-unused-vars`. This is equivalent to inserting the individual elements of `exampleConfigs` in order, such as:
79
+
80
+
```js
81
+
// eslint.config.js
82
+
importexampleConfigsfrom"eslint-config-example";
83
+
import { defineConfig } from"eslint/config";
84
+
85
+
exportdefaultdefineConfig([
86
+
87
+
// insert individual elements instead of an array
88
+
exampleConfigs[0],
89
+
exampleConfigs[1],
90
+
exampleConfigs[2],
91
+
92
+
// your modifications
93
+
{
94
+
rules: {
95
+
"no-unused-vars":"warn"
96
+
}
97
+
}
98
+
]);
99
+
```
71
100
72
101
### Apply a Config Array to a Subset of Files
73
102
74
-
You can apply a config array to just a subset of files by using the `map()` method to add a `files`key to each config object. For example:
103
+
You can apply a config array to just a subset of files by using the `extends`key. For example:
75
104
76
105
```js
77
106
// eslint.config.js
78
107
importexampleConfigsfrom"eslint-config-example";
108
+
import { defineConfig } from"eslint/config";
79
109
80
-
exportdefault [
81
-
...exampleConfigs.map(config=> ({
82
-
...config,
83
-
files: ["**/src/safe/*.js"]
84
-
})),
85
-
86
-
// your modifications
110
+
exportdefaultdefineConfig([
87
111
{
112
+
files: ["**/src/safe/*.js"],
113
+
extends: [exampleConfigs],
88
114
rules: {
89
115
"no-unused-vars":"warn"
90
116
}
91
117
}
92
-
];
118
+
]);
93
119
```
94
120
95
121
Here, each config object in `exampleConfigs` is applied only to files that match the pattern "`**/src/safe/*.js"`.
0 commit comments