eslint-plugin-babel is an ESLint plugin that provides alternative implementations of core ESLint rules designed to work with experimental JavaScript features supported by Babel. While babel-eslint adapts ESLint to work with Babel's parsing, this plugin re-implements problematic rules to prevent false positives when using modern JavaScript syntax like decorators, optional chaining, class properties, and other experimental features.
npm install eslint-plugin-babel --save-devNo direct imports needed - configured as an ESLint plugin:
{
"plugins": ["babel"]
}{
"plugins": ["babel"],
"rules": {
"babel/new-cap": 1,
"babel/camelcase": 1,
"babel/no-invalid-this": 1,
"babel/object-curly-spacing": 1,
"babel/quotes": 1,
"babel/semi": 1,
"babel/no-unused-expressions": 1,
"babel/valid-typeof": 1
}
}eslint-plugin-babel follows the standard ESLint plugin structure:
rules and rulesConfig objectseslint-rule-composer to wrap core ESLint rules with custom filtering logicThe plugin requires ESLint >=4.0.0 and Node >=4.
Main plugin export providing ESLint rule definitions and configurations.
module.exports = {
rules: {
// All available rules (active and deprecated)
},
rulesConfig: {
// Default rule configurations (all disabled by default)
}
};Eight enhanced rules that provide Babel-compatible alternatives to core ESLint rules.
// Core active rules with Babel syntax support
const activeRules = [
'new-cap', // Ignores capitalized decorators (@Decorator)
'camelcase', // Supports optional chaining (bar?.a_b)
'no-invalid-this', // Allows 'this' in class properties
'object-curly-spacing', // Handles export syntax variations
'quotes', // Supports JSX fragment shorthand (<>foo</>;)
'semi', // Handles async iteration and class properties
'no-unused-expressions', // Supports do expressions and optional chaining
'valid-typeof' // Allows BigInt typeof checks
];All active rules support the same options as their corresponding core ESLint rules.
// Example rule configurations with options
"babel/new-cap": [1, { "capIsNew": false }]
"babel/camelcase": [1, { "properties": "never", "ignoreDestructuring": true }]
"babel/semi": [2, "always"]Seven deprecated rules that redirect to newer ESLint or plugin alternatives.
// Deprecated rules (show warnings when used)
const deprecatedRules = [
'array-bracket-spacing', // Use built-in since eslint@3.9.0
'arrow-parens', // Use built-in since eslint@3.10.0
'flow-object-type', // Use flowtype/object-type-delimiter
'func-params-comma-dangle', // Use built-in comma-dangle since eslint@3.8.0
'generator-star-spacing', // Use built-in since eslint@3.6.0
'object-shorthand', // Use built-in since eslint@0.20.0
'no-await-in-loop' // Use built-in since eslint@3.12.0
];