eslint-plugin-babel
raw JSON โ 5.3.1 verified Sat Apr 25 auth: no javascript
An ESLint plugin companion to babel-eslint that re-implements core ESLint rules to handle Babel experimental features such as decorators, optional chaining, class properties, do expressions, BigInt, and JSX fragment syntax. Version 5.3.1 is the latest stable release; it requires ESLint >=4.0.0 and Node >=4. The plugin replaces problematic built-in rules with Babel-aware versions to avoid false positives/negatives, and several older rules have been deprecated in favor of native ESLint rules or eslint-plugin-flowtype. It uses eslint-rule-composer for rule composition, is actively maintained, and supports autofix for some rules (marked with ๐ ).
Common errors
error Error: Failed to load plugin 'babel': Cannot find module 'eslint-plugin-babel' โ
cause eslint-plugin-babel is not installed as a dev dependency.
fix
Run 'npm install eslint-plugin-babel --save-dev'
error Error: ESLint configuration error: Unknown rule "babel/new-cap" โ
cause The 'babel' plugin is not listed in the 'plugins' section of your ESLint config.
fix
Add '"plugins": ["babel"]' to your .eslintrc.
error Error: Cannot find module '@babel/eslint-parser' (or babel-eslint) โ
cause The plugin expects babel-eslint or @babel/eslint-parser as a parser, but it's missing.
fix
Install babel-eslint: 'npm install babel-eslint --save-dev' and set "parser": "babel-eslint" in your ESLint config.
error Warning: Rule 'babel/flow-object-type' is deprecated โ
cause The rule was deprecated in favor of eslint-plugin-flowtype's object-type-delimiter.
fix
Replace 'babel/flow-object-type' with 'flowtype/object-type-delimiter' and install eslint-plugin-flowtype.
Warnings
breaking v5.0.0 dropped support for ESLint <4.0.0 and Node <4. Use eslint-rule-composer for rules. โ
fix Upgrade ESLint to >=4.0.0 and Node to >=4. Ensure eslint-rule-composer is installed.
deprecated Rules babel/generator-star-spacing, babel/object-shorthand, babel/arrow-parens, babel/func-params-comma-dangle, babel/array-bracket-spacing, babel/flow-object-type, and babel/no-await-in-loop are deprecated. โ
fix Use corresponding core ESLint rules (or eslint-plugin-flowtype for flow-object-type) as listed in the README.
deprecated babel/no-await-in-loop was deprecated in v4.1.1 and removed in later versions. โ
fix Use core ESLint rule no-await-in-loop (supported since ESLint 3.12.0).
deprecated babel/flow-object-type was deprecated in v4.0.0. Use eslint-plugin-flowtype's object-type-delimiter rule instead. โ
fix Install eslint-plugin-flowtype and use flowtype/object-type-delimiter.
gotcha Do not enable both the core rule and the babel rule for the same rule name โ they will conflict. โ
fix Disable the core rule (e.g., 'new-cap': 'off') when using the babel version.
gotcha The plugin does not automatically apply to all files; you must add the babel plugin to your ESLint config. โ
fix Add '"plugins": ["babel"]' to your .eslintrc.
Install
npm install eslint-plugin-babel yarn add eslint-plugin-babel pnpm add eslint-plugin-babel Imports
- babel/new-cap wrong
// wrong: using core rule with Babel code - false positives on decoratorscorrect// In .eslintrc: "rules": { "babel/new-cap": "error" } - babel/camelcase wrong
// wrong: core camelcase flags optional chaining like foo?.a_bcorrect// In .eslintrc: "rules": { "babel/camelcase": "error" } - babel/no-invalid-this wrong
// wrong: core no-invalid-this errors on class properties using thiscorrect// In .eslintrc: "rules": { "babel/no-invalid-this": "error" } - babel/semi wrong
// wrong: core semi fails on for await and class propertiescorrect// In .eslintrc: "rules": { "babel/semi": "error" } - babel/object-curly-spacing wrong
// wrong: core object-curly-spacing complains on export x from 'mod'correct// In .eslintrc: "rules": { "babel/object-curly-spacing": "error" }
Quickstart
npm install eslint-plugin-babel --save-dev
// .eslintrc.json
{
"plugins": ["babel"],
"rules": {
"babel/new-cap": "error",
"babel/camelcase": "error",
"babel/no-invalid-this": "error",
"babel/semi": "error"
}
}
// Disable the original rules in your config if they conflict:
{
"rules": {
"new-cap": "off",
"camelcase": "off",
"no-invalid-this": "off",
"semi": "off"
}
}