diff --git a/docs/eslint-plugin.md b/docs/eslint-plugin.md index 3c52ce3743..86318f2cc1 100644 --- a/docs/eslint-plugin.md +++ b/docs/eslint-plugin.md @@ -10,22 +10,28 @@ Companion rules for [`@babel/eslint-parser`](./eslint-parser.md). `@babel/eslint for use with Babel, but it can't change the built-in rules to support experimental features. `@babel/eslint-plugin` re-implements problematic rules so they do not give false positives or negatives. -> Requires Node.js 10.13 or greater - ## Install ```shell npm2yarn npm install @babel/eslint-plugin --save-dev ``` -Load the plugin in your ESLint config and enable all the rules you would like to use (remember to disable the original ones as well!). +## Predefined configurations + +`@babel/eslint-plugin` has two predefined configurations: + +- `recommended`: Enables all companion rules when the reimplemented built-in rules are in the [`js/recommended` predefined configuration](https://eslint.org/docs/latest/use/configure/configuration-files#use-predefined-configurations). -```js title=eslint.config.js +- `all`: Enables all companion rules. + +```js title="eslint.config.js" import babelParser from "@babel/eslint-parser"; import babelPlugin from "@babel/eslint-plugin"; +import js from "@eslint/js"; import { defineConfig } from "eslint/config"; export default defineConfig([ + js.configs.recommended, { files: ["**/*.js", "**/*.cjs", "**/*.mjs"], languageOptions: { @@ -34,12 +40,58 @@ export default defineConfig([ plugins: { babel: babelPlugin }, + ...babelPlugin.configs.recommended, + }, +]); +``` + +## Rules + +Each rule corresponds to a core `eslint` rule and has the same options. + +✅ means the [`recommended`](#predefined-configurations) config from `@babel/eslint-plugin` enables this rule. + +🔧 means it's autofixable with `--fix`. + + +| Name | Description | R | F | +| --- | --- | --- | --- | +| new-cap | handles decorators (`@Decorator`) | | | +| no-empty | handles `do` expressions | ✅ | 🔧 | +| no-undef | handles class accessor properties (`class A { accessor x = 2 }`) | | | +| no-unused-expressions | handles `do` expressions | | | + +### Configure Rules + +Load the plugin in your ESLint config and enable all the rules you would like to use (remember to disable the built-in ones as well!). + +```js title="eslint.config.js" +import js from "@eslint/js"; +import babelParser from "@babel/eslint-parser"; +import babelPlugin from "@babel/eslint-plugin"; +import { defineConfig } from "eslint/config"; + +export default defineConfig([ + js.configs.recommended, + { + files: ["**/*.js", "**/*.cjs", "**/*.mjs"], + languageOptions: { + parser: babelParser, + }, + plugins: { + js, + babel: babelPlugin + }, rules: { + // Disable built-in rules in @eslint/js "new-cap": "off", + "no-empty": "off", "no-undef": "off", "no-unused-expressions": "off", + // Enable Babel rules "babel/new-cap": "error", + "babel/no-empty": "error", "babel/no-undef": "error", "babel/no-unused-expressions": "error", } @@ -47,20 +99,6 @@ export default defineConfig([ ]); ``` - - -## Rules - -Each rule corresponds to a core `eslint` rule and has the same options. - -🛠: means it's autofixable with `--fix`. - -- `@babel/new-cap`: handles decorators (`@Decorator`) -- `@babel/no-undef`: handles class accessor properties (`class A { accessor x = 2 }`) -- `@babel/no-unused-expressions`: handles `do` expressions - - - ## TypeScript While [`@babel/eslint-parser`](https://github.com/babel/babel/tree/main/eslint/babel-eslint-parser) can parse TypeScript, we don't currently support linting TypeScript using the rules in [`@babel/eslint-plugin`](https://github.com/babel/babel/tree/main/eslint/babel-eslint-plugin). This is because the TypeScript community has centered around [`@typescript-eslint`](https://github.com/typescript-eslint/typescript-eslint) and we want to avoid duplicate work. Additionally, since [`@typescript-eslint`](https://github.com/typescript-eslint/typescript-eslint) uses TypeScript under the hood, its rules can be made type-aware, which is something Babel doesn't have the ability to do. diff --git a/docs/v8-migration.md b/docs/v8-migration.md index 66f001f8ce..d532664006 100644 --- a/docs/v8-migration.md +++ b/docs/v8-migration.md @@ -390,7 +390,7 @@ The following syntax plugins are no longer needed, you can safely remove them fr **Migration**: Specify the minor version of core-js 3 that you use to ensure latest features will be polyfilled if required. For example, - ```js title=babel.config.mjs + ```js title="babel.config.mjs" import corejsPackage from "core-js/package.json" with { type: "json" } export default { "presets": [[