Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d3e81e3

Browse files
kecrilynzakaslumirlumirfasttime
authored
docs: Always recommend to include a files property (#20158)
* docs: Always recommend to include a files property * update * update * update * clean * Apply suggestion from @lumirlumir Co-authored-by: 루밀LuMir <[email protected]> * update `templates/formatter-examples.md.ejs` * Update docs/src/use/configure/combine-configs.md --------- Co-authored-by: Nicholas C. Zakas <[email protected]> Co-authored-by: 루밀LuMir <[email protected]> Co-authored-by: Francesco Trotta <[email protected]>
1 parent 15f5c7c commit d3e81e3

File tree

6 files changed

+22
-72
lines changed

6 files changed

+22
-72
lines changed

docs/src/extend/plugin-migration-flat-config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ import example from "eslint-plugin-example";
190190
export default defineConfig([
191191
// use recommended config and provide your own overrides
192192
{
193-
files: ["**/*.js"],
193+
files: ["**/*.js", "**/*.cjs", "**/*.mjs"],
194194
plugins: {
195195
example,
196196
},

docs/src/extend/plugins.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ import example from "eslint-plugin-example";
153153

154154
export default defineConfig([
155155
{
156+
files: ["**/*.js"], // any patterns you want to apply the config to
156157
plugins: {
157158
example,
158159
},

docs/src/use/configure/combine-configs.md

Lines changed: 7 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11,94 +11,32 @@ In many cases, you won't write an ESLint config file from scratch, but rather, y
1111

1212
## Apply a Config Object
1313

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:
1515

1616
```js
1717
// eslint.config.js
1818
import js from "@eslint/js";
1919
import { defineConfig } from "eslint/config";
2020

2121
export default defineConfig([
22-
js.configs.recommended,
2322
{
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-
import js from "@eslint/js";
40-
import { defineConfig } from "eslint/config";
41-
42-
export default defineConfig([
43-
{
44-
files: ["**/src/safe/*.js"],
23+
files: ["**/*.js"],
4524
plugins: {
4625
js,
4726
},
4827
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-
import exampleConfigs from "eslint-config-example";
62-
import { defineConfig } from "eslint/config";
63-
64-
export default defineConfig([
65-
// insert array directly
66-
exampleConfigs,
67-
68-
// your modifications
69-
{
7028
rules: {
7129
"no-unused-vars": "warn",
7230
},
7331
},
7432
]);
7533
```
7634

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-
import exampleConfigs from "eslint-config-example";
82-
import { defineConfig } from "eslint/config";
83-
84-
export default defineConfig([
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`.
9836

99-
### Apply a Config Array to a Subset of Files
37+
## Apply a Config Array
10038

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:
10240

10341
```js
10442
// eslint.config.js
@@ -107,7 +45,7 @@ import { defineConfig } from "eslint/config";
10745

10846
export default defineConfig([
10947
{
110-
files: ["**/src/safe/*.js"],
48+
files: ["**/*.js"],
11149
extends: [exampleConfigs],
11250
rules: {
11351
"no-unused-vars": "warn",
@@ -116,4 +54,4 @@ export default defineConfig([
11654
]);
11755
```
11856

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`.

docs/src/use/configure/configuration-files.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ With this configuration, the `semi` rule is enabled for all files that match the
137137

138138
::: important
139139
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.
140143
:::
141144

142145
#### Specifying files with arbitrary extensions

docs/src/use/formatters/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ import { defineConfig } from "eslint/config";
4242
import js from "@eslint/js";
4343

4444
export default defineConfig([
45-
js.configs.recommended,
4645
{
46+
files: ["**/*.js"],
47+
plugins: {
48+
js,
49+
},
50+
extends: ["js/recommended"],
4751
rules: {
4852
"consistent-return": 2,
4953
"indent" : [1, 4],

templates/formatter-examples.md.ejs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ import { defineConfig } from "eslint/config";
4141
import js from "@eslint/js";
4242

4343
export default defineConfig([
44-
js.configs.recommended,
4544
{
45+
files: ["**/*.js"],
46+
plugins: {
47+
js,
48+
},
49+
extends: ["js/recommended"],
4650
rules: {
4751
"consistent-return": 2,
4852
"indent" : [1, 4],

0 commit comments

Comments
 (0)