@babel/eslint-plugin
Version:
Companion rules for @babel/eslint-parser
55 lines (40 loc) ⢠2.13 kB
Markdown
# /eslint-plugin
Companion rules for `/eslint-parser`. `@babel/eslint-parser` does a great job at adapting `eslint`
for use with Babel, but it can't change the built-in rules to support experimental features.
`/eslint-plugin` re-implements problematic rules so they do not give false positives or negatives.
> Requires Node 10.13 or greater
### Install
```sh
npm install /eslint-plugin --save-dev
```
Load the plugin in your `.eslintrc.json` file:
```json
{
"plugins": ["@babel"]
}
```
Finally enable all the rules you would like to use (remember to disable the
original ones as well!).
```json
{
"rules": {
"@babel/new-cap": "error",
"@babel/no-invalid-this": "error",
"@babel/no-undef": "error",
"@babel/no-unused-expressions": "error",
"@babel/object-curly-spacing": "error",
"@babel/semi": "error"
}
}
```
### Rules
Each rule corresponds to a core `eslint` rule and has the same options.
š : means it's autofixable with `--fix`.
- `/new-cap`: handles decorators (` `)
- `/no-invalid-this`: handles class fields and private class methods (`class A { a = this.b; }`)
- `/no-undef`: handles class accessor properties (`class A { accessor x = 2 }`)
- `/no-unused-expressions`: handles `do` expressions
- `/object-curly-spacing`: handles `export * as x from "mod";` (š )
- `/semi`: Handles class properties (š )
## TypeScript
While [`/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.