or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

index.mddocs/

ESLint Plugin ES5

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.

Package Information

  • Package Name: eslint-plugin-es5
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install --save-dev eslint-plugin-es5
  • ESLint Compatibility: ESLint >= 3.0.0

Core Imports

ESLint plugin registration (no direct imports needed):

// .eslintrc.json
{
  "plugins": ["es5"]
}

For programmatic access:

const eslintPluginEs5 = require("eslint-plugin-es5");

Basic Usage

Using Preset Configurations

// .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"
  ]
}

Using Individual Rules

// .eslintrc.json
{
  "plugins": ["es5"],
  "rules": {
    "es5/no-arrow-functions": "error",
    "es5/no-classes": "warn",
    "es5/no-template-literals": "error"
  }
}

Architecture

ESLint Plugin ES5 follows the standard ESLint plugin architecture:

  • Plugin Structure: Exports configs and rules objects that ESLint can consume
  • Rule Implementation: Each rule is implemented as a separate module that exports a meta object and create function
  • AST-based Analysis: Rules analyze JavaScript Abstract Syntax Tree (AST) nodes to detect ES2015+ features
  • Configuration System: Pre-built configurations bundle related rules for common use cases
  • Fixable Rules: Seven rules support automatic code transformation using ESLint's fixer API
  • Schema Validation: Rules with options use JSON Schema for parameter validation

The plugin integrates seamlessly with existing ESLint configurations and supports both individual rule usage and preset configurations.

Capabilities

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;
}

no-es2015 Configuration

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"]
}

no-es2016 Configuration

Targeted preset that forbids ES2016 features, specifically the exponentiation operator (**).

// Usage  
{
  "extends": ["plugin:es5/no-es2016"]
}

Individual ESLint Rules

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;
}

Core Language Feature Rules

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"

Variable Declaration and Scoping Rules

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"

Function Parameter Rules

no-default-parameters

// Forbids default function parameters
"es5/no-default-parameters": "error"

no-rest-parameters

// Forbids rest parameters (...args)
"es5/no-rest-parameters": "error"

Object and Property Rules

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"

Spread and Iteration Rules

no-spread (πŸ”§ Fixable)

// Forbids spread syntax (...)
"es5/no-spread": "error"

no-for-of

// Forbids for-of loops
"es5/no-for-of": "error"

String and Template Rules

no-template-literals (πŸ”§ Fixable)

// Forbids template literal strings
"es5/no-template-literals": "error"

Literal and Numeric Rules

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"

Built-in Method Rules

no-es6-methods

// Forbids ES2015 methods for Array and String
"es5/no-es6-methods": "error"

Forbids the following ES2015 methods:

  • Array methods: find, findIndex, copyWithin, values, fill
  • String methods: startsWith, endsWith, includes, repeat

Note: 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: Array.from, Array.of
  • Math: Math.acosh, Math.hypot, Math.trunc, Math.imul, Math.sign
  • Number: Number.isNaN, Number.isFinite, Number.isInteger, Number.isSafeInteger, Number.parseFloat, Number.parseInt
  • Object: Object.assign, Object.is, Object.getOwnPropertySymbols, Object.setPrototypeOf

Symbol and Unicode Rules

no-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"

Rule Configuration Options

no-block-scoping Options

interface BlockScopingOptions {
  let?: boolean;     // Allow let declarations
  const?: boolean;   // Allow const declarations
}

// Usage
"es5/no-block-scoping": ["error", { "let": true }]

no-es6-static-methods Options

interface StaticMethodsOptions {
  exceptMethods?: string[];  // Array of method names to allow
}

// Usage
"es5/no-es6-static-methods": ["error", { "exceptMethods": ["Math.imul", "Object.assign"] }]

Fixable Rules

The following rules support ESLint's --fix option and can automatically repair code:

  • no-arrow-functions - Converts to function expressions with proper this binding
  • no-binary-and-octal-literals - Converts to decimal equivalents
  • no-destructuring - Expands destructuring to individual assignments
  • no-shorthand-properties - Expands to full property syntax
  • no-spread - Converts spread syntax to appropriate alternatives
  • no-template-literals - Converts to string concatenation
  • no-unicode-code-point-escape - Converts to standard escape sequences

Integration Patterns

With Create React App (Ejected)

// .eslintrc.js
module.exports = {
  extends: [
    'react-app',
    'plugin:es5/no-es2015'
  ],
  rules: {
    // Override specific rules if needed
    'es5/no-arrow-functions': 'warn'
  }
};

With Legacy Build Systems

// .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"
  }
}

Gradual Migration

// .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
  }
}