Skip to content

Commit 7ddb095

Browse files
nzakasmdjermanovic
andauthored
feat: Export defineConfig, globalIgnores (#19487)
* feat: Export defineConfig, globalIgnores fixes #19116 * Remove unneeded fixtures * Fix tyeps * Update docs/src/use/configure/combine-configs.md Co-authored-by: Milos Djermanovic <[email protected]> * Update docs/src/use/configure/configuration-files.md Co-authored-by: Milos Djermanovic <[email protected]> * Update docs/src/use/configure/ignore.md Co-authored-by: Milos Djermanovic <[email protected]> * cleanup docs --------- Co-authored-by: Milos Djermanovic <[email protected]>
1 parent 86c5f37 commit 7ddb095

File tree

13 files changed

+479
-282
lines changed

13 files changed

+479
-282
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,17 @@ This ensures that pnpm installs dependencies in a way that is more compatible wi
7272
You can configure rules in your `eslint.config.js` files as in this example:
7373

7474
```js
75-
export default [
75+
import { defineConfig } from "eslint/config";
76+
77+
export default defineConfig([
7678
{
7779
files: ["**/*.js", "**/*.cjs", "**/*.mjs"],
7880
rules: {
7981
"prefer-const": "warn",
8082
"no-constant-binary-expression": "error"
8183
}
8284
}
83-
];
85+
]);
8486
```
8587

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

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

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,80 +16,106 @@ If you are importing an object from another module, in most cases, you can just
1616
```js
1717
// eslint.config.js
1818
import js from "@eslint/js";
19+
import { defineConfig } from "eslint/config";
1920

20-
export default [
21+
export default defineConfig([
2122
js.configs.recommended,
2223
{
2324
rules: {
2425
"no-unused-vars": "warn"
2526
}
2627
}
27-
];
28+
]);
2829
```
2930

3031
Here, the `js.configs.recommended` predefined configuration is applied first and then another configuration object adds the desired configuration for `no-unused-vars`.
3132

32-
### Apply a Config Object to a Subset of Files
33+
### Apply a Configuration to a Subset of Files
3334

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

3637
```js
3738
// eslint.config.js
3839
import js from "@eslint/js";
40+
import { defineConfig } from "eslint/config";
3941

40-
export default [
42+
export default defineConfig([
4143
{
42-
...js.configs.recommended,
43-
files: ["**/src/safe/*.js"]
44+
files: ["**/src/safe/*.js"],
45+
plugins: {
46+
js
47+
},
48+
extends: ["js/recommended"]
4449
}
45-
];
50+
]);
4651
```
4752

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

5055
## Apply a Config Array
5156

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

5459
```js
5560
// eslint.config.js
5661
import exampleConfigs from "eslint-config-example";
62+
import { defineConfig } from "eslint/config";
5763

58-
export default [
59-
...exampleConfigs,
64+
export default defineConfig([
65+
66+
// insert array directly
67+
exampleConfigs,
6068

6169
// your modifications
6270
{
6371
rules: {
6472
"no-unused-vars": "warn"
6573
}
6674
}
67-
];
75+
]);
6876
```
6977

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

72101
### Apply a Config Array to a Subset of Files
73102

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

76105
```js
77106
// eslint.config.js
78107
import exampleConfigs from "eslint-config-example";
108+
import { defineConfig } from "eslint/config";
79109

80-
export default [
81-
...exampleConfigs.map(config => ({
82-
...config,
83-
files: ["**/src/safe/*.js"]
84-
})),
85-
86-
// your modifications
110+
export default defineConfig([
87111
{
112+
files: ["**/src/safe/*.js"],
113+
extends: [exampleConfigs],
88114
rules: {
89115
"no-unused-vars": "warn"
90116
}
91117
}
92-
];
118+
]);
93119
```
94120

95121
Here, each config object in `exampleConfigs` is applied only to files that match the pattern "`**/src/safe/*.js"`.

0 commit comments

Comments
 (0)