ESLint Plugin ES5 is an ESLint plugin that provides comprehensive rules and configurations to restrict ES2015+ JavaScript features for ES5 compatibility. It's designed for environments that cannot use Babel transpilation or need to maintain strict ES5 compliance due to legacy browser support or runtime constraints.
npm install --save-dev eslint-plugin-es5ESLint plugin registration (no direct imports needed):
// .eslintrc.json
{
"plugins": ["es5"]
}For programmatic access:
const eslintPluginEs5 = require("eslint-plugin-es5");// .eslintrc.json - Forbid all ES2015 features
{
"extends": ["plugin:es5/no-es2015"]
}
// .eslintrc.json - Forbid ES2016 features only
{
"extends": ["plugin:es5/no-es2016"]
}
// .eslintrc.json - Combine with other configs
{
"extends": [
"eslint:recommended",
"plugin:es5/no-es2015"
]
}// .eslintrc.json
{
"plugins": ["es5"],
"rules": {
"es5/no-arrow-functions": "error",
"es5/no-classes": "warn",
"es5/no-template-literals": "error"
}
}ESLint Plugin ES5 follows the standard ESLint plugin architecture:
configs and rules objects that ESLint can consumemeta object and create functionThe plugin integrates seamlessly with existing ESLint configurations and supports both individual rule usage and preset configurations.
Pre-configured rule sets for common ES5 compatibility scenarios.
interface PluginConfig {
plugins: string[];
rules: Record<string, number>;
}
// Available configurations
configs: {
"no-es2015": PluginConfig;
"no-es2016": PluginConfig;
}Comprehensive preset that forbids all ES2015+ features. Includes 21 rules covering arrow functions, classes, template literals, destructuring, modules, and other modern syntax.
// Usage
{
"extends": ["plugin:es5/no-es2015"]
}Targeted preset that forbids ES2016 features, specifically the exponentiation operator (**).
// Usage
{
"extends": ["plugin:es5/no-es2016"]
}Fine-grained control over specific ES2015+ features with 22 individual rules.
// Plugin structure
interface ESLintPlugin {
configs: {
"no-es2015": PluginConfig;
"no-es2016": PluginConfig;
};
rules: Record<string, ESLintRule>;
}
interface ESLintRule {
meta: {
docs: { description: string };
fixable?: "code";
schema: any[];
};
create: (context: ESLintContext) => ESLintVisitor;
}
interface ESLintContext {
report(options: {
node: any;
message: string;
fix?: (fixer: any) => any;
}): void;
getSourceCode(): any;
}
interface ESLintVisitor {
[key: string]: (node: any) => void;
}no-arrow-functions (π§ Fixable)
// Forbids arrow function expressions
"es5/no-arrow-functions": "error"Automatically converts arrow functions to function expressions, handling this binding appropriately.
no-classes
// Forbids ES2015 class declarations and expressions
"es5/no-classes": "error"no-generators
// Forbids generator functions
"es5/no-generators": "error"no-modules
// Forbids ES2015 module syntax (import/export)
"es5/no-modules": "error"no-block-scoping
// Forbids let and const declarations
"es5/no-block-scoping": "error"
// With options to allow specific declarations
"es5/no-block-scoping": ["error", { "let": true }]no-destructuring (π§ Fixable)
// Forbids destructuring assignments and declarations
"es5/no-destructuring": "error"no-default-parameters
// Forbids default function parameters
"es5/no-default-parameters": "error"no-rest-parameters
// Forbids rest parameters (...args)
"es5/no-rest-parameters": "error"no-computed-properties
// Forbids computed property names in objects
"es5/no-computed-properties": "error"no-shorthand-properties (π§ Fixable)
// Forbids shorthand property names in object literals
"es5/no-shorthand-properties": "error"no-object-super
// Forbids super keyword usage
"es5/no-object-super": "error"no-spread (π§ Fixable)
// Forbids spread syntax (...)
"es5/no-spread": "error"no-for-of
// Forbids for-of loops
"es5/no-for-of": "error"no-template-literals (π§ Fixable)
// Forbids template literal strings
"es5/no-template-literals": "error"no-binary-and-octal-literals (π§ Fixable)
// Forbids binary (0b) and octal (0o) numeric literals
"es5/no-binary-and-octal-literals": "error"no-exponentiation-operator
// Forbids exponentiation operator (**)
"es5/no-exponentiation-operator": "error"no-es6-methods
// Forbids ES2015 methods for Array and String
"es5/no-es6-methods": "error"Forbids the following ES2015 methods:
find, findIndex, copyWithin, values, fillstartsWith, endsWith, includes, repeatNote: Methods are allowed when used with Lodash (_) or jQuery ($) objects.
no-es6-static-methods
// Forbids ES2015 static methods for Array, Math, Number, and Object
"es5/no-es6-static-methods": "error"
// With options to allow specific methods
"es5/no-es6-static-methods": ["error", { "exceptMethods": ["Math.imul"] }]Forbids the following ES2015 static methods:
Array.from, Array.ofMath.acosh, Math.hypot, Math.trunc, Math.imul, Math.signNumber.isNaN, Number.isFinite, Number.isInteger, Number.isSafeInteger, Number.parseFloat, Number.parseIntObject.assign, Object.is, Object.getOwnPropertySymbols, Object.setPrototypeOfno-typeof-symbol
// Forbids typeof foo === 'symbol' checks
"es5/no-typeof-symbol": "error"no-unicode-code-point-escape (π§ Fixable)
// Forbids Unicode code point escapes in strings
"es5/no-unicode-code-point-escape": "error"no-unicode-regex
// Forbids Unicode flag in regular expressions
"es5/no-unicode-regex": "error"interface BlockScopingOptions {
let?: boolean; // Allow let declarations
const?: boolean; // Allow const declarations
}
// Usage
"es5/no-block-scoping": ["error", { "let": true }]interface StaticMethodsOptions {
exceptMethods?: string[]; // Array of method names to allow
}
// Usage
"es5/no-es6-static-methods": ["error", { "exceptMethods": ["Math.imul", "Object.assign"] }]The following rules support ESLint's --fix option and can automatically repair code:
no-arrow-functions - Converts to function expressions with proper this bindingno-binary-and-octal-literals - Converts to decimal equivalentsno-destructuring - Expands destructuring to individual assignmentsno-shorthand-properties - Expands to full property syntaxno-spread - Converts spread syntax to appropriate alternativesno-template-literals - Converts to string concatenationno-unicode-code-point-escape - Converts to standard escape sequences// .eslintrc.js
module.exports = {
extends: [
'react-app',
'plugin:es5/no-es2015'
],
rules: {
// Override specific rules if needed
'es5/no-arrow-functions': 'warn'
}
};// .eslintrc.json
{
"env": {
"browser": true,
"es5": true
},
"extends": ["plugin:es5/no-es2015"],
"rules": {
// Allow specific modern features if your build system handles them
"es5/no-template-literals": "off"
}
}// .eslintrc.json - Start with warnings, move to errors
{
"plugins": ["es5"],
"rules": {
"es5/no-arrow-functions": "warn",
"es5/no-classes": "warn",
"es5/no-template-literals": "error" // Strict on this one
}
}