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: docs/src/use/configure/combine-configs.md
+7-69Lines changed: 7 additions & 69 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,94 +11,32 @@ In many cases, you won't write an ESLint config file from scratch, but rather, y
11
11
12
12
## Apply a Config Object
13
13
14
-
If you are importing a [config object](../core-concepts/glossary#config-object) from another module, in most cases, you can just pass the object directly to the `defineConfig()` helper. For example, you can use the recommended rule configurations for JavaScript by importing the `recommended` config and using it in your array:
14
+
If you are importing a [config object](../core-concepts/glossary#config-object) from another module, you can apply it 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 imported object. For example:
15
15
16
16
```js
17
17
// eslint.config.js
18
18
importjsfrom"@eslint/js";
19
19
import { defineConfig } from"eslint/config";
20
20
21
21
exportdefaultdefineConfig([
22
-
js.configs.recommended,
23
22
{
24
-
rules: {
25
-
"no-unused-vars":"warn",
26
-
},
27
-
},
28
-
]);
29
-
```
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`.
32
-
33
-
### Apply a Configuration to a Subset of Files
34
-
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:
36
-
37
-
```js
38
-
// eslint.config.js
39
-
importjsfrom"@eslint/js";
40
-
import { defineConfig } from"eslint/config";
41
-
42
-
exportdefaultdefineConfig([
43
-
{
44
-
files: ["**/src/safe/*.js"],
23
+
files: ["**/*.js"],
45
24
plugins: {
46
25
js,
47
26
},
48
27
extends: ["js/recommended"],
49
-
},
50
-
]);
51
-
```
52
-
53
-
Here, the `js/recommended` config object is applied only to files that match the pattern "`**/src/safe/*.js"`.
54
-
55
-
## Apply a Config Array
56
-
57
-
If you are importing a [config array](../core-concepts/glossary#config-array) from another module, pass the array directly to the `defineConfig()` helper. Here's an example:
58
-
59
-
```js
60
-
// eslint.config.js
61
-
importexampleConfigsfrom"eslint-config-example";
62
-
import { defineConfig } from"eslint/config";
63
-
64
-
exportdefaultdefineConfig([
65
-
// insert array directly
66
-
exampleConfigs,
67
-
68
-
// your modifications
69
-
{
70
28
rules: {
71
29
"no-unused-vars":"warn",
72
30
},
73
31
},
74
32
]);
75
33
```
76
34
77
-
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:
78
-
79
-
```js
80
-
// eslint.config.js
81
-
importexampleConfigsfrom"eslint-config-example";
82
-
import { defineConfig } from"eslint/config";
83
-
84
-
exportdefaultdefineConfig([
85
-
// insert individual elements instead of an array
86
-
exampleConfigs[0],
87
-
exampleConfigs[1],
88
-
exampleConfigs[2],
89
-
90
-
// your modifications
91
-
{
92
-
rules: {
93
-
"no-unused-vars":"warn",
94
-
},
95
-
},
96
-
]);
97
-
```
35
+
Here, the `"js/recommended"` predefined configuration is applied to files that match the pattern `"**/*.js"` first and then adds the desired configuration for `no-unused-vars`.
98
36
99
-
###Apply a Config Array to a Subset of Files
37
+
## Apply a Config Array
100
38
101
-
You can apply a config array (an array of configuration objects) to just a subset of files by using the `extends` key. For example:
39
+
If you are importing a [config array](../core-concepts/glossary#config-array) from another module, you can apply a config array (an array of configuration objects) to just a subset of files by using the `extends` key. For example:
102
40
103
41
```js
104
42
// eslint.config.js
@@ -107,7 +45,7 @@ import { defineConfig } from "eslint/config";
107
45
108
46
exportdefaultdefineConfig([
109
47
{
110
-
files: ["**/src/safe/*.js"],
48
+
files: ["**/*.js"],
111
49
extends: [exampleConfigs],
112
50
rules: {
113
51
"no-unused-vars":"warn",
@@ -116,4 +54,4 @@ export default defineConfig([
116
54
]);
117
55
```
118
56
119
-
Here, each config object in `exampleConfigs` is applied only to files that match the pattern "`**/src/safe/*.js"`.
57
+
Here, the `exampleConfigs`shareable configuration is applied to files that match the pattern "`**/*.js"` first and then another configuration object adds the desired configuration for `no-unused-vars`.
Copy file name to clipboardExpand all lines: docs/src/use/configure/configuration-files.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -137,6 +137,9 @@ With this configuration, the `semi` rule is enabled for all files that match the
137
137
138
138
::: important
139
139
By default, ESLint lints files that match the patterns `**/*.js`, `**/*.cjs`, and `**/*.mjs`. Those files are always matched unless you explicitly exclude them using [global ignores](#globally-ignoring-files-with-ignores).
140
+
If your configuration object includes other patterns, the rules in configuration objects without a `files` key will also apply to these patterns.
141
+
142
+
Therefore, when using ESLint for non-JS files as well, it is more appropriate to create a configuration object that includes `files: ["**/*.js", "**/*.cjs", "**/*.mjs"]` and place the relevant rules there.
0 commit comments