New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Migrating eslint-env
configuration comments
#17390
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,6 +255,63 @@ export default [ | |
]; | ||
``` | ||
|
||
In the eslintrc config system it was possible to use `eslint-env` configuration comments to define globals for a file. | ||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this part. This issue suggests that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the intent was that these would be reported as linter warnings. We aren't doing that yet, but that's where we are going. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks! I've updated the wording in issue #13481 to clarify. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll also try adding this next as I'm sure this will be helpful for people as they transition to the new config system. |
||
For this reason, when migrating from eslintrc to flat config, `eslint-env` configuration comments must be removed from all files. | ||
fasttime marked this conversation as resolved.
Show resolved
Hide resolved
|
||
They can be either replaced with equivalent but more verbose `global` configuration comments, or dropped in favor of `globals` definitions in the config file. | ||
|
||
For example, when using eslintrc, a file to be linted could look like this: | ||
|
||
```javascript | ||
// tests/my-file.js | ||
|
||
/* eslint-env mocha */ | ||
|
||
describe("unit tests", () => { | ||
it("should pass", () => { | ||
// ... | ||
}); | ||
}); | ||
``` | ||
|
||
In the above example, `describe` and `it` would be recognized as global identifiers because of the `/* eslint-env mocha */` comment. | ||
|
||
The same effect can be achieved with flat config with a `global` configuration comment, e.g.: | ||
|
||
```javascript | ||
// tests/my-file.js | ||
|
||
/* global describe, it -- Globals defined by Mocha */ | ||
|
||
describe("unit tests", () => { | ||
it("should pass", () => { | ||
// ... | ||
}); | ||
}); | ||
``` | ||
|
||
Another option is to remove the comment from the file being linted and define the globals in the configuration, for example: | ||
|
||
```javascript | ||
// eslint.config.js | ||
|
||
import globals from "globals"; | ||
|
||
export default [ | ||
// ...other config | ||
{ | ||
files: [ | ||
"tests/**" | ||
], | ||
languageOptions: { | ||
globals: { | ||
...globals.mocha | ||
} | ||
} | ||
} | ||
]; | ||
``` | ||
|
||
### Predefined Configs | ||
|
||
In eslintrc files, use the `extends` property to use predefined configs. ESLint comes with two predefined configs that you can access as strings: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a new heading here like
### `eslint-env` Configuration Comments
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'd add a new heading.