Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda73e58

Browse files
fasttimenzakas
andauthored
docs: Migratingeslint-env configuration comments (#17390)
* docs: Migrating `eslint-env` configuration comments* "must" -> "should"Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com>* Add heading---------Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com>
1 parent10e9cfa commitda73e58

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

‎docs/src/use/configure/migration-guide.md‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,65 @@ export default [
255255
];
256256
```
257257

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+
258317
###Predefined Configs
259318

260319
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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp