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/migration-guide.md
+59
Original file line number
Diff line number
Diff line change
@@ -255,6 +255,65 @@ export default [
255
255
];
256
256
```
257
257
258
+
### `eslint-env` Configuration Comments
259
+
260
+
In the eslintrc config system it was possible to use `eslint-env` configuration comments to define globals for a file.
261
+
These comments are no longer recognized when linting with flat config: in a future version of ESLint, `eslint-env` comments will be reported as errors.
262
+
For this reason, when migrating from eslintrc to flat config, `eslint-env` configuration comments should be removed from all files.
263
+
They can be either replaced with equivalent but more verbose `global` configuration comments, or dropped in favor of `globals` definitions in the config file.
264
+
265
+
For example, when using eslintrc, a file to be linted could look like this:
266
+
267
+
```javascript
268
+
// tests/my-file.js
269
+
270
+
/* eslint-env mocha */
271
+
272
+
describe("unit tests", () => {
273
+
it("should pass", () => {
274
+
// ...
275
+
});
276
+
});
277
+
```
278
+
279
+
In the above example, `describe` and `it` would be recognized as global identifiers because of the `/* eslint-env mocha */` comment.
280
+
281
+
The same effect can be achieved with flat config with a `global` configuration comment, e.g.:
282
+
283
+
```javascript
284
+
// tests/my-file.js
285
+
286
+
/* global describe, it -- Globals defined by Mocha */
287
+
288
+
describe("unit tests", () => {
289
+
it("should pass", () => {
290
+
// ...
291
+
});
292
+
});
293
+
```
294
+
295
+
Another option is to remove the comment from the file being linted and define the globals in the configuration, for example:
296
+
297
+
```javascript
298
+
// eslint.config.js
299
+
300
+
importglobalsfrom"globals";
301
+
302
+
exportdefault [
303
+
// ...other config
304
+
{
305
+
files: [
306
+
"tests/**"
307
+
],
308
+
languageOptions: {
309
+
globals: {
310
+
...globals.mocha
311
+
}
312
+
}
313
+
}
314
+
];
315
+
```
316
+
258
317
### Predefined Configs
259
318
260
319
In eslintrc files, use the `extends` property to use predefined configs. ESLint comes with two predefined configs that you can access as strings:
0 commit comments