| 1 | # @babel/eslint-plugin |
| 2 | |
| 3 | Companion rules for `@babel/eslint-parser`. `@babel/eslint-parser` does a great job at adapting `eslint` |
| 4 | for use with Babel, but it can't change the built-in rules to support experimental features. |
| 5 | `@babel/eslint-plugin` re-implements problematic rules so they do not give false positives or negatives. |
| 6 | |
| 7 | > Requires Node 10.13 or greater |
| 8 | |
| 9 | ### Install |
| 10 | |
| 11 | ```sh |
| 12 | npm install @babel/eslint-plugin --save-dev |
| 13 | ``` |
| 14 | |
| 15 | Load the plugin in your `.eslintrc.json` file: |
| 16 | |
| 17 | ```json |
| 18 | { |
| 19 | "plugins": ["@babel"] |
| 20 | } |
| 21 | ``` |
| 22 | |
| 23 | Finally enable all the rules you would like to use (remember to disable the |
| 24 | original ones as well!). |
| 25 | |
| 26 | ```json |
| 27 | { |
| 28 | "rules": { |
| 29 | "@babel/new-cap": "error", |
| 30 | "@babel/no-invalid-this": "error", |
| 31 | "@babel/no-unused-expressions": "error", |
| 32 | "@babel/object-curly-spacing": "error", |
| 33 | "@babel/semi": "error" |
| 34 | } |
| 35 | } |
| 36 | ``` |
| 37 | |
| 38 | ### Rules |
| 39 | |
| 40 | Each rule corresponds to a core `eslint` rule and has the same options. |
| 41 | |
| 42 | 🛠: means it's autofixable with `--fix`. |
| 43 | |
| 44 | - `@babel/new-cap`: handles decorators (`@Decorator`) |
| 45 | - `@babel/no-invalid-this`: handles class fields and private class methods (`class A { a = this.b; }`) |
| 46 | - `@babel/no-unused-expressions`: handles `do` expressions |
| 47 | - `@babel/object-curly-spacing`: handles `export * as x from "mod";` (🛠) |
| 48 | - `@babel/semi`: Handles class properties (🛠) |
| 49 | |
| 50 | ## TypeScript |
| 51 | |
| 52 | 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. |